21

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.

user2930353
  • 333
  • 1
  • 2
  • 6
  • [Potentially related question](https://stackoverflow.com/questions/46638293/ignore-system-headers-in-clang-tidy) – Increasingly Idiotic May 15 '18 at 17:19
  • I've had success using `-header-filter`. [Docs](http://clang.llvm.org/extra/clang-tidy/#using-clang-tidy) – Justin May 15 '18 at 17:20
  • 3
    Doesn't `-header-filter` make clang-tidy check those header files? I do not want to check them at all, which I thought was the default? – user2930353 May 15 '18 at 17:22
  • Yes by default it should ignore all headers, although I'm only familiar with newer versions. Maybe when passing -I directly it behaves differently then using `compile-commands.json`? – ricco19 May 15 '18 at 17:36
  • 3
    `clang-diagnostic-error` seems to be special and is not a regular check. Header filtering doesn't work for me either. – letmaik Aug 07 '19 at 19:24
  • Use `-isystem/path/to/include` instead of `-I`. This suppresses all warnings from that file and everything it includes. – ingomueller.net Aug 08 '19 at 07:58
  • Good question! Seems to be an easy problem to solve, still have no clue how to get rid of this errors. – Maciej Haj Apr 14 '21 at 22:26

2 Answers2

5

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

pablo285
  • 2,460
  • 4
  • 14
  • 38
0

I'm not sure if this would not break something later, so just at your own risk. I managed to "solve" this (because it was just a matter of having an error on the Problems list) on VSCode:

"C_Cpp.codeAnalysis.clangTidy.args": [
  "--extra-arg=-ferror-limit=1"
]

This makes clang-tidy tell the compiler to throw just one error and give up. So clang-tidy will parse whatever is left.

I know was for VSCode, but the argument can be used in other IDEs.

franzbischoff
  • 150
  • 5
  • 15