title: clang-tidy - ignore third party headers code
body: <p>I'm using CMake for my project and I wanted to introduce clang-tidy checks to the project.</p>
  <p>I'm using for this purpose <code>CMAKE_CXX_CLANG_TIDY</code> and <code>.clang-tidy</code> file for checks setup.</p>
  <p>I wanted to use warnings-as-errors to have reliable way in CI to check whether commit introduces some new violations. Unfortunately I have some problems with enabling checks due to 3rd-party libraries.</p>
  <p>PLEASE LOOK AT EDIT2!</p>
  <p>For example I use <code>Eigen</code> which is header-only library. Due to this fact I get some warnings in my code eg. &quot;a_file.cpp&quot;</p>
  <pre><code>/snap/cmake/301/bin/cmake -E __run_co_compile --tidy=&quot;clang-tidy;--extra-arg-before=--driver-mode=g++&quot; --source=../../a_file.cpp -- /usr/bin/clang++ -DEIGEN_MPL2_ONLY -DEIGEN_STACK_ALLOCATION_LIMIT=16384 -I../../SomePath -I../../SomePath2 -isystem ../../path_to/include/Eigen -m64 -stdlib=libc++ -g -fPIC -std=c++11 -MD -MT a_file.cpp.o -MF a_file.cpp.o.d -o a_file.cpp.o -c a_file.cpp                                                                            
  ../../path_to/include/Eigen/Eigen/src/Core/Swap.h:89:36: error: Assigned value is garbage or undefined [clang-analyzer-core.uninitialized.Assign,-warnings-as-errors] 
  a_file.cpp:279:5: note: Loop condition is true.  Entering loop body                            
      for( unsigned int i = 0; i &lt; 100; ++i )                                                                                                                                                                                                                         
      ^                                                                                                                                                                                                                                                                 
  a_file.cpp:282:13: note: Calling move assignment operator for 'Matrix&lt;float, 3, 1, 0, 3, 1&gt;'   
              some_name = Vector3f( GetRandom( fDummy ),GetRandom( fDummy ), GetRandom( fDummy ) );  
  </code></pre>
  <p>I'm a bit out of ideas how to ignore this kind of problems as <code>header-filter</code> doesn't seem to resolve this issue - for other checks [bugprone-xxx] I have similar issues. What are my options besides adding <code>//NO-LINT</code> everywhere?</p>
  <p>Edit: added a bit of context to error.</p>
  <p>EDIT2:</p>
  <p>As I still struggle with correct handling for <code>clang-tidy</code> I've prepared a repository to show the example problem.</p>
  <p><a href="https://github.com/MaciejPatro/test_clang_tidy" rel="nofollow noreferrer">https://github.com/MaciejPatro/test_clang_tidy</a></p>
  <p>This is a minimal repository with 2 header files, and one cpp files that uses <code>doctest</code>. I use two checks there: <code>clang-analyzer-cplusplus*,google-readability-todo</code> - first one demonstrating the problem with <code>doctest</code> inclusion and second one because it's the simplest one to create a &quot;bug&quot;.</p>
  <p>some_header.h</p>
  <pre class="lang-cpp prettyprint-override"><code>void else_after_return() {
    // TODO wrong hpp some
  }
  </code></pre>
  <p>other_header.h</p>
  <pre class="lang-cpp prettyprint-override"><code>void wrong_function() {
    // TODO wrong hpp other
  }
  </code></pre>
  <p>my_test.cpp</p>
  <pre class="lang-cpp prettyprint-override"><code>#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
  
  #include &lt;doctest/doctest.h&gt;
  #include &lt;some_header.h&gt;
  #include &lt;other_header.h&gt;
  
  TEST_CASE(&quot;a test&quot;)
  {
    // TODO wrong cpp
    else_after_return();
    wrong_function();
    CHECK(5 != 7);
  }
  </code></pre>
  <p>There are 3 tests that give these results:</p>
  <ol>
  <li><p>Ignore header files (no --header-filter specified).
  I can see:</p>
  <pre><code>/home/pmac/projects/test_clang_tidy/source/tests/my_test.cpp:9:3: warning: missing username/bug in TODO [google-readability-todo]
  </code></pre>
  <p>Which is expected</p>
  </li>
  <li><p>Allow all header files ( --header-filter=.* )
  I can see:</p>
  <pre><code>/home/pmac/projects/test_clang_tidy/source/include/other_header.h:5:3: warning: missing username/bug in TODO [google-readability-todo]
  /home/pmac/projects/test_clang_tidy/source/include/some_header.h:5:3: warning: missing username/bug in TODO [google-readability-todo]
  /home/pmac/projects/test_clang_tidy/source/tests/my_test.cpp:9:3: warning: missing username/bug in TODO [google-readability-todo]
  </code></pre>
  <p>Which makes sense for me</p>
  </li>
  <li><p>Only header files with &quot;some in name&quot; (--header-filter=.<em>some.</em>)</p>
  <pre><code>/home/pmac/projects/test_clang_tidy/source/include/some_header.h:5:3: warning: missing username/bug in TODO [google-readability-todo]
  /home/pmac/projects/test_clang_tidy/source/tests/my_test.cpp:9:3: warning: missing username/bug in TODO [google-readability-todo]
  </code></pre>
  <p>Everything seems fine</p>
  </li>
  </ol>
  <p>Next 3 tests add the second check <code>clang-analyzer-cplusplus</code> which is visible in <code>doctest</code>. Now regardless of the settings provided to <code>clang-tidy</code> I get additionally a warning from <code>doctest</code> MACRO <code>DOCTEST_DO_BINARY_EXPRESSION_COMPARISON</code> which is expanded from <code>CHECK</code>:</p>
  <pre><code>/home/pmac/.conan/data/doctest/2.4.6/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/doctest/doctest.h:1239:9: warning: Potential leak of memory pointed to by field 'ptr' [clang-analyzer-cplusplus.NewDeleteLeaks]
  </code></pre>
  <p>I want the warning from <code>doctest</code> being filtered out - unfortunately none of settings (--header-filter, nor including it as system header <code>-isystem</code>) allows me to ignore it.</p>
  <p>Here is the full command line how the my_test.cpp is compiled (to confirm that <code>doctest</code> header is included with <code>-isystem</code>)</p>
  <pre><code>/home/pmac/.local/lib/python3.8/site-packages/cmake/data/bin/cmake -E __run_co_compile --tidy=&quot;clang-tidy-12;-checks=-*,clang-analyzer-cplusplus*,google-readability-todo;--header-filter=.*some.*;--extra-arg-before=--driver-mode=g++&quot; --source=../source/tests/my_test.cpp -- /usr/bin/c++  -I../source/include -isystem /home/pmac/.conan/data/doctest/2.4.6/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -g -std=gnu++2a -MD -MT source/CMakeFiles/test_clang_tidy_tests.dir/tests/my_test.cpp.o -MF source/CMakeFiles/test_clang_tidy_tests.dir/tests/my_test.cpp.o.d -o source/CMakeFiles/test_clang_tidy_tests.dir/tests/my_test.cpp.o -c ../source/tests/my_test.cpp
  </code></pre>
  <p>Is there any other way to filter out the warning generated by MACROs included from a 3rd party library? I don't want to remove checks in my tests because of 3rdparty library.</p>
  <p>To change &quot;Tests&quot; in repository comment/uncomment lines in <code>https://github.com/MaciejPatro/test_clang_tidy/blob/master/CMakeLists.txt</code></p>
  <pre><code>set(CMAKE_CXX_CLANG_TIDY &quot;clang-tidy-12;-checks=-*,google-readability-todo&quot;)
  #set(CMAKE_CXX_CLANG_TIDY &quot;clang-tidy-12;-checks=-*,google-readability-todo;--header-filter=.*&quot;)
  #set(CMAKE_CXX_CLANG_TIDY &quot;clang-tidy-12;-checks=-*,google-readability-todo;--header-filter=.*some.*&quot;)
  
  # Something works wrong here!
  #set(CMAKE_CXX_CLANG_TIDY &quot;clang-tidy-12;-checks=-*,clang-analyzer-cplusplus*,google-readability-todo)
  #set(CMAKE_CXX_CLANG_TIDY &quot;clang-tidy-12;-checks=-*,clang-analyzer-cplusplus*,google-readability-todo;--header-filter=.*&quot;)
  #set(CMAKE_CXX_CLANG_TIDY &quot;clang-tidy-12;-checks=-*,clang-analyzer-cplusplus*,google-readability-todo;--header-filter=.*some.*&quot;)
  </code></pre>