Created
July 11, 2016 20:43
-
-
Save uucidl/f6203d2623798c26fb9ad0ba1d409276 to your computer and use it in GitHub Desktop.
Pragma disabling warning 4668 are not honored in time by the MSVC pre-processor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
REM a normal compilation runs through | |
cl.exe main.cpp /Z7 /nologo /c -DWIN32 -W4 -WX -Wall -wd4514 | |
REM however the pre-processor fails because of -WX and C4668 | |
cl.exe main.cpp /Z7 /nologo /c -DWIN32 -W4 -WX -Wall -wd4514 -E |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if defined(_MSC_VER) | |
#define PUSH_LENIENT_WARNINGS \ | |
__pragma(warning(push)) \ | |
__pragma(warning(disable: 4668)) \ | |
__pragma(warning(disable: 4100)) | |
#define POP_LENIENT_WARNINGS \ | |
__pragma(warning(pop)) | |
#endif | |
// # A section of code where warnings are relaxed. | |
// This would for instance be a third-party library header file, for instance | |
PUSH_LENIENT_WARNINGS | |
#if SOME_RARE_DEFINE_TRIGGERING_C4668 | |
#error "HELLO" | |
#endif | |
inline int function_triggering_unused_args_warning(int a) { | |
return 42; | |
} | |
POP_LENIENT_WARNINGS | |
// End of section | |
// # Now regular part of the code where warnings should apply in full: | |
extern "C" int puts(const char*); | |
extern "C" int exit(int); | |
#define UNUSED(__symbol) (void)(__symbol) | |
int main(int argc, char **argv) | |
{ | |
UNUSED(argc); | |
UNUSED(argv); | |
puts("hello, world"); | |
#if WIN32 | |
#if defined(SOME_RARE_DEFINE_TRIGGERING_C4668) | |
#endif | |
puts("On win32"); | |
#endif | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment