2

I'm trying to enable some warnings that detail potential security problems through a pragma. The warnings are those listed by Jon Sturgeon in “Off By Default” Compiler Warnings in Visual C++:

# pragma warning (enable: 4191 4242 4263 4264 4265 4266 4302 4826 4905 4906 4928)

I'm getting a warning under Visual Studio (2010 to be exact) for the above pragma:

ClCompile:
  pch.cpp
  ... config.h(238): warning C4615: #pragma warning : unknown user warning type

It appears there is no enable or on for pragma warning. There is a once, but I want to see all instances of the potential problems, and not just one.

Microsoft's documentation on warning does not appear to discuss the topic of enabling warnings.

I can't really use # pragma warning (default: ...) because they are off by default. I don't want to modify each of the solution's configurations because the solution has 4 projects, 6 configurations and 4 platforms. So I have 80+ of them to change (the cross product of the selections).

How do I enable select warnings through the pragma?

jww
  • 97,681
  • 90
  • 411
  • 885
  • possible a duplicate ? http://stackoverflow.com/questions/4151908/enable-a-single-warning-in-visual-studio – Marged Jun 29 '15 at 08:00
  • Thanks Marged. Its close, but I don't think so because the two answers offer: (1) do it in the solution's configuration, and (2) use `pragma warning (default: ...)`. I specifically want to avoid it in the configuration because the solution has 4 projects, 6 configurations and 4 platforms. That means I have to potentially touch it in 80 places. – jww Jun 29 '15 at 08:11
  • It should be `error` not `enable` as `in #pragma warning (error: 4191 4242 4263 4264 4265 4266 4302 4826 4905 4906 4928)` – Barmak Shemirani Jun 29 '15 at 08:21
  • @BarmakShemirani - But won't `error` stop the compile? I want the compile to complete. My requirement (for release engineering) is a clean compile. I don't care what happens up until that point. The developers would tar and feather me if I stopped their compilation process for no reason. – jww Jun 29 '15 at 08:34
  • You are right. That's no good. How about #pragma warning( push, 4 ) ... followed by #pragma pop? I guess you have already seen that though – Barmak Shemirani Jun 29 '15 at 08:38
  • 3
    From the MSDN link, if you `#pragma warning(X: a b c d)`, where X is 1,2,3,4 and 'a b c d' are your warnings, it says `This also turns on a specified warning that is off by default.` .. so would `# pragma warning (1: 4191 4242 4263 4264 4265 4266 4302 4826 4905 4906 4928)` and enable a warning level of 1 not suffice? Then do a `# pragma warning (default: 4191 4242 4263 4264 4265 4266 4302 4826 4905 4906 4928)` which would put them back in the default level/state .. I could be reading that wrong as I don't usually mess with the MS specific `pragmas` ..? – txtechhelp Jun 29 '15 at 08:42
  • Check out here: [Enable a single warning in Visual Studio](https://stackoverflow.com/questions/4151908/enable-a-single-warning-in-visual-studio) – KaiserKatze Aug 12 '19 at 11:49
  • Hmmm... This is on the first page for using a search engine with `site:stackoverflow.com GCC pragma warnings as errors`... It is probably the right-hand panel that introduces the noise. – Peter Mortensen Oct 21 '22 at 23:23

0 Answers0