3

I'd like to compile my project with /Wall.

When I do this I get tons of warning from third-party code (boost libraries, other system header files). The only place where I include these third-party header files is in my precompiled header (stdafx.h).

I tried this (in stdafx.h)

#pragma warning(push,3)
    // include all the third-party headers here
#pragma warning(pop)

to compile all third-party code with warning level 3.

However I still get hundreds of warnings from files like math.h, xmemory, vector, string_generator.hpp(boost.uuid), placeholders.hpp (boost.asio), ...

How can I make sure to compile all third-party code with warning level 3 while compiling my own code with all warnings enabled?

Robert Hegner
  • 9,014
  • 7
  • 62
  • 98
  • Some of the warnings are just silly, like warnings that things that didn't use to work has now been fixed. You will have to disable select warnings. See this other question [http://stackoverflow.com/questions/4292352/msvc-stop-warnings-in-headers](http://stackoverflow.com/questions/4292352/msvc-stop-warnings-in-headers). – Bo Persson May 23 '11 at 11:57

3 Answers3

1

3rd party code is modified less frequently, so it's a good idea to have all these includes in your StdAfx.h and then your above solution would suppress their warnings.

Either that or create some other wrapper header files that use the above pragma around the actual includes to the libraries you use.

I can't think of a third way. I say shove them all in the stdafx (and where they're actually included, too. remember that stdafx is an optimization - not a replacement for careful selective including within your source files)

Assaf Lavie
  • 73,079
  • 34
  • 148
  • 203
  • As I mentioned in my question, all third-party headers are included in `stdafx.h` only. In my source files I only include `stdafx.h` and my own project-specific headers, which can change more frequently. So I don't understand why I'm still getting warnings from third-party code even tough I enclosed all these includes with `#pragma warning(push,3)`. – Robert Hegner May 23 '11 at 11:35
  • 1
    How certain are you that no other includes are sneaking in there somehow? Maybe you have some compiler switch that auto-includes some stuff? What happens when you just compile stdafx.cpp? Do you get the warnings? If not, what happens when you compile an empty .cpp file that just includes stdafx.h? You can work backwards this way until you figure out where these includes are actually happening. – Assaf Lavie May 23 '11 at 11:37
  • 1
    also, you might want to use this compiler switch to see how your includes are actually working: http://msdn.microsoft.com/en-us/library/hdkef6tk.aspx – Assaf Lavie May 23 '11 at 11:38
  • Compiling `stdafx.cpp` only gives no warnings and compiling every source file separatly gives only warnings which are related to my code. But now I see what's happening: All these warnings from third-party code are generated by the linker. Things like "function not inlined", ... – Robert Hegner May 23 '11 at 11:57
  • Is there anything I can do against these linker warnings? – Robert Hegner May 23 '11 at 11:57
  • I'm not sure what happened before. When I build the project now, I also get warnings during the compilation of stdafx.cpp. But when I right-click on stdafx.cpp and click "compile", there are no warnings. You can see the build output here: [link](https://docs.google.com/leaf?id=0B89qp_QRBuXQZGRiOWQ2MjYtZThlMS00NTdkLWFkMTAtZDA0ZjRjNTNiYjM2&hl=en_US), and you can find my stdafx.h here: [link](https://docs.google.com/leaf?id=0B89qp_QRBuXQZmMyYjBkNTctZGE3MC00OWVmLWE4ZTYtMzQ0ZWFkMzExZjJl&hl=en_US). stdafx.cpp does only contain the include of stdafx.h – Robert Hegner May 23 '11 at 12:56
  • btw, the output for the linking step starts at line 291 – Robert Hegner May 23 '11 at 12:58
1

/W4 is more realistic than /Wall. I routinely use stl, tr1, and windows headers with /W4. I don't know about boost.

The reason wrapping the headers with the #pragma isn't enough is that some of the warnings are generated when instantiating templates or expanding macros (or perhaps even with inlining).

Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
0

Check all of the includes that your files pull in. It may be that one of them likely resets warnings to their default state. I've seen this with either MFC or ATL headers that come with VC++ - some warnings are disabled and then re-enabled with a "default" call specifier rather than using a push/pop pair.

sean e
  • 11,792
  • 3
  • 44
  • 56