3

I want to disable Code Analysis for a CPP file. There is a way to exclude header files.

https://msdn.microsoft.com/en-us/library/zyhb0b82(v=vs.100).aspx

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

I want to disable for CPP file. Can some one help me, if there is a way to do this.

Thanks Santhi

sreeR
  • 59
  • 6
  • I would expect you do it in the same way... just push the pragma at the top of your source file. – mah Apr 29 '16 at 21:09
  • I tried, it didnt work. When Code analysis run I see there is an error . So I wanted to disable CL for a CPP file. disasm.cpp ..\external\Detours\src\disasm.cpp(633): fatal error C1001: An internal error has occurred in the compiler. (compiler file 'msc1ast.cpp', line 1325) INTERNAL COMPILER ERROR in 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64\CL.exe' – sreeR May 02 '16 at 03:29

1 Answers1

-1

I know it's a very old thread - but I recently encounter an almost similar need (disable code analysis for part of the source). At least with VisualStudio-2019, the symbol CODE_ANALYSIS seems to be defined when the analysis is running.

So hopefully, you could solve your error with a simple preprocessor directive:

#ifndef CODE_ANALYSIS
#  include <third-party include files here>
#endif

I have to admit that I'm not sure if the additional /DCODE_ANALYSIS on the command line of CL comes "natively" or from one of my plugins.

Flo
  • 16
  • 3
  • 2
    How does this help? Code analysis still requires the code to compile. So if the third-party header is required to compile the code, all you'll get are many more errors instead of annoying warnings. – 0xC0000022L Feb 08 '22 at 11:26