【问题标题】:Ignore [clang-diagnostic-error] clang-tidy caused by 3rd party headers忽略由 3rd 方标头引起的 [clang-diagnostic-error] clang-tidy
【发布时间】:2018-10-25 15:00:51
【问题描述】:

我在开发中使用 clang-tidy 作为“linter”工具。我开始将第 3 方软件集成到我的代码中,当我使用以下方法包含他们的头文件时:

-I/path/to/include 

产生了大量错误,我什至还没有#include 标头。

error: too many errors emitted, stopping now [clang-diagnostic-error]
...
/path/to/include/wchar.h:81:1: error: unknown type name 'wint_t' [clang-diagnostic-error]
wint_t fgetwc(FILE *__stream);
^
/path/to/include/wchar.h:81:15: error: unknown type name 'FILE' [clang-diagnostic-error]
wint_t fgetwc(FILE *__stream);
              ^
...

我使用以下代码编译我的程序:

/usr/bin/clang-tidy-4.0 /path/to/main.cpp -checks=-*,cppcoreguidelines* -- -lang-c++ -I/path/to/include -std=gnu++11 -Wall -Werror -O0 -g -D<define variables>

似乎这些“clang-diagnostic-errors”并没有停止编译,因为它继续编译并且运行良好。是否有标志可以关闭/抑制此错误?我不想看,因为我没有写这些头文件。

如果我去掉-I/path/to/include 的参数,一切都可以正常编译,没有错误。

【问题讨论】:

  • 我已经成功使用-header-filterDocs
  • -header-filter 不让 clang-tidy 检查那些头文件吗?我根本不想检查它们,我认为这是默认设置?
  • 是的,默认情况下它应该忽略所有标题,尽管我只熟悉较新的版本。也许当直接传递 -I 时,它的行为与使用 compile-commands.json 不同?
  • clang-diagnostic-error 好像很特别,不是定期检查。标题过滤对我也不起作用。

标签: c++ header-files linter clang-tidy


【解决方案1】:

没有办法忽略 clang-diagnostic-error,因为它基本上是编译器错误。

为了使clang-tidy 工作,分析的代码需要能够被clang 后端编译以生成 AST(抽象语法树)。

问题是您包含了无法由 clang 编译的标头(我猜是用于 MSVC 的 windows 标头)。

【讨论】:

    猜你喜欢
    • 2021-06-19
    • 2020-07-20
    • 2018-03-20
    • 2022-07-12
    • 2020-12-30
    • 2019-10-01
    • 1970-01-01
    • 2016-05-17
    • 1970-01-01
    相关资源
    最近更新 更多