views:

82

answers:

4

I've got a third-party library that generates a ton of warnings, even under /W3. Is there a way for me to tell the compiler, "disable C4244 for any file included from this directory, or its subdirectories"? Of course, I don't want to disable the warning in our own codebase, nor do I want to have to track down every possible include and wrap it with #pragma warning(...

A: 

I'm not sure whether you meant you do not want to wrap your include statements with #pragma directives or did not want to spend time tracking down the right directive. If its the latter, then this is what I've done in the past:

#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#endif

#include "MyHeader.h"

#ifdef _MSC_VER
#pragma warning( default : 4244 ) /* Reset to default state */
#endif

Regards, Ashish.

Praetorian
Sorry, it was the former. I know how to disable warnings through #pragma already.
mos
This should work. The compiler memorizes the warning pragma that was in effect when it compiled the declaration.
Hans Passant
@Hans: This might turn off the warnings generated by MyHeader.h, but it doesn't answer my question. I don't want to search a couple hundred files for the several dozen library includes, and then wrap them with the #pragmas.
mos
@mos: why do you have to search? The compiler reminds you that you missed one.
Hans Passant
Praetorian
+1  A: 

You could try removing the 3rd party project from your include path. Then create a sub-dir that has the same dir structure and header files as the 3rd party project, so that all of the #includes now find your headers instead. Then in each fake header xxxx.h you set the pragma's then include the real xxxx.h header, then clear the pragma. To avoid recursively including the same file you would have to add an extra dir to the #include.

Personally, I'd just go through your project and add the pragma's.

jon hanson
A: 

You can put flags e.g /wd4600 in VS Project Settings > Command-line Options to tell the complier to suppress specific Complier Warnings

Dave18
This misses the part that he says about, "I don't want to disable the warning in our own codebase."
Brooks Moses
A: 

I hate to answer my own question here, but I'm afraid that the "correct" answer in this case is: it's not possible.

mos
@mos Yes. I've even tried to abuse the pre-processor to generate a INCLUDE macro that disabled warnings but that doesn't seem possible also. The only way out to have some sensible output I think is to grep the compiler warning output but for now I'm just living with all warnings.
Vitor Py