1

I'm running clang-tidy on a header file header.h. However as some of the warning outputs, it's outputting system headers:

.../include/c++/8/bits/std_abs.h:46:8: error: expected identifier or '(' [clang-diagnostic-error]
extern "C++"
../include/c++/8/cctype:62:1: error: unknown type name 'namespace' [clang-diagnostic-error]
namespace std
../include/c++/8/cctype:62:14: error: expected ';' after top level declarator [clang-diagnostic-error]
namespace std
..
etc

The problem: I don't want to see the warnings for anything other than the source file I'm scanning, for either a source file or header file.

I've tried implementing the fix here (What is the correct way of providing header-filter for clang-tidy in Cmake?) using --header-filter but it didnt work. I added the path to the header file that I was scanning in the regex, but I was still seeing the system header warnings.

helloworld95
  • 366
  • 7
  • 17
  • From my experience, `clang-diagnostic-error` cannot be filtered out by `clang` itself, since it comes from clang backend. – R2RT Apr 26 '21 at 22:31
  • @R2RT Thanks for the reply. So, are you implying that it could be a rules-pack thing and not a headers file issue? If these clang-diagnostic-errors cannot be filtered out, then scanning certain files would be practically useless in my opinion. – helloworld95 Apr 26 '21 at 22:57
  • 1
    The thing is, in your log there is compilation error. What means there is no scanning done at all, because `clang-tidy` operates on AST, which cannot be generated from invalid code. So filtering out such error only hides the problem of including error-prone file. You seem to include MSVC header file in non-mscv compatibility mode. Try out solutions from http://clang-developers.42468.n3.nabble.com/Parsing-VC-headers-with-tool-libtooling-td4048253.html – R2RT Apr 27 '21 at 06:01

1 Answers1

1

For clang-tidy to work your code needs to be compile-able by the clang backend to generate an AST. This is apparently not the case since clang-diagnostic-error is basically a compilation error.

The problem is you are including headers that cannot be compiled by clang, there is no way to filter that out.

pablo285
  • 2,460
  • 4
  • 14
  • 38