Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 637
user2930353 Avatar asked May 15 '18 17:05

user2930353


People also ask

How do I turn off clang diagnostic error?

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

How do I disable clang-tidy checks?

If you must enable or disable particular checks, use the clang-tidy command-line format in your . clang-tidy files. The command-line format specifies a comma-separated list of positive and negative globs: positive globs add subsets of checks, and negative globs (prefixed with - ) remove subsets of checks.

What is clang diagnostic?

Allows you to suppress, enable, or change the severity of specific diagnostic messages from within your code. For example, you can suppress a particular diagnostic message when compiling one specific function.

Where does clang look for?

Some header files ( stddef. h , stdarg. h , and others) are shipped with Clang — these are called builtin includes. Clang searches for them in a directory relative to the location of the clang binary.


1 Answers

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

like image 63
pablo285 Avatar answered Oct 12 '22 12:10

pablo285