Ignore [clang-diagnostic-error] clang-tidy caused by 3rd party headers

11,133

There is no way to ignore clang-diagnostic-error since it's basically a compiler error.

For clang-tidy to work the analyzed code needs to be compile-able by the clang backend to generate an AST(Abstract syntax tree).

The problem is you are including headers that cannot be compiled by clang (I'm guessing windows headers intended for MSVC).

Share:
11,133
user2930353
Author by

user2930353

Updated on June 06, 2022

Comments

  • user2930353
    user2930353 about 2 years

    I am using clang-tidy as a "linter" tool in development. I started to integrate 3rd party software into my code and when I include their header files using:

    -I/path/to/include 
    

    tons of errors are generated, I haven't even #include the headers yet.

    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);
                  ^
    ...
    

    I compile my program using:

    /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>
    

    It seems that these "clang-diagnostic-errors" do not stop compilation, as it continues to compile and runs fine. Is there a flag to turn this error off/suppress it? I do not want to see it since I did not write these header files.

    If I get rid of the argument -I/path/to/include everything compiles fine with no errors.