14

I have setup buildbot to compile my Qt/C++ application with the /analyze flag.

However the analysis is also delving into the qt headers which I don't care about:

c:\qt\qt-everywhere-opensource-src-4.8.1\src\corelib\tools\qvector.h(547) : warning C6011: Dereferencing NULL pointer 'x.p': Lines: 474, 475, 476, 477, 478, 480, 491, 493, 497, 498, 499, 500, 503, 504, 518, 519, 520, 521, 522, 525, 545, 547

Whats the best way to exclude these files en mass?

(Please note I am not using the IDE, I am looking for a command line, switch or code change)

James McNellis
  • 348,265
  • 75
  • 913
  • 977
Phil Hannent
  • 12,047
  • 17
  • 71
  • 118
  • Possible duplicate of [How to suppress warnings in external headers in Visual C++](http://stackoverflow.com/questions/2541984/how-to-suppress-warnings-in-external-headers-in-visual-c) – cambunctious Jul 07 '16 at 15:52

1 Answers1

15

You can disable all code analysis warnings for a particular block of code using #pragma warning in your code. MSDN provides the following example:

#include <codeanalysis\warnings.h>
#pragma warning( push )
#pragma warning ( disable : ALL_CODE_ANALYSIS_WARNINGS )
#include <third-party include files here>
#pragma warning( pop )

(See "How to: Enable and Disable Code Analysis for Specific C/C++ Warnings" for more information.)

To the best of my knowledge, there is no way to disable warnings from particular header files using only command line options.

parsley72
  • 8,449
  • 8
  • 65
  • 98
James McNellis
  • 348,265
  • 75
  • 913
  • 977
  • 1
    Unfortunately, the pragma disables analysis warnings at the time a header gets included the first time. This means that if your third-party includes windows headers, you won't get any analysis warnings later. In my case, one such header is `` - of course the same applies to C++ std library headers. Which makes `ALL_CODE_ANALYSIS_WARNINGS` kind of useless, or again very hard to use... In this sense I find it easier to leave all warnings enabled and make use of the Error List output window, which allows grouping by path. – klaus triendl Jun 26 '18 at 18:29
  • This is so elegant, thank you so much! @klaustriendl that could be fixed with PCH files I guess. – metablaster Jun 03 '20 at 14:39