How to disable a particular unknown #pragma warning (GCC and/or Clang)

Viewed 33298

I know how to disable all unknown #pragma warnings. The answer was given, for example, in How can I disable #pragma warnings?.

Is there a way to disable an 'unknown pragma' warning for one particular pragma? For example, if I disable warning for #pragma ugubugu the following code:

#pragma ugubugu
#pragma untiunti

int main() {return 0;}

when compiled with either:

g++ pragma.cpp -Wall
clang++ pragma.cpp -Wall

should produce a single warning:

warning: ignoring #pragma untiunti

Maybe, for example, is there a simple way to register a custom pragma which would do nothing?

It would be great to know if there is such an option is Visual Studio too, but that is less important.


"But why ultimately is he playing with custom pragmas?"

My source code is parsed by two compilers. In one of those, there is a special #pragma that is unknown to the other. Of course, I could probably put #ifdef COMPILER_IDENTIFICATION_MACRO ... #endif around every instance of the #pragma, but that would be cumbersome.

3 Answers

I assume you want to disable the pragma warnings because it's something that is valid on one platform but not another. If that's the case, you can use macros to selectively enable the pragma, eliminating the need to suppress the warning.

For example, if you want the pragma on Visual C++ only, you can do:

#if defined(_MSC_VER)
#    define SAFE_PRAGMA_UGUBUGU __pragma(ugubugu)
#else
#    define SAFE_PRAGMA_UGUBUGU 
#endif

And then, you can write

SAFE_PRAGMA_UGUBUGU
#pragma untiunti   
int main() {return 0;}
Related