Skip to content

Instantly share code, notes, and snippets.

@uucidl
Created July 11, 2016 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uucidl/f6203d2623798c26fb9ad0ba1d409276 to your computer and use it in GitHub Desktop.
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
@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
#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