2

I cannot make the method to temporarily disable warnings in GCC (see How to disable GCC warnings for a few lines of code) work, at least not for the "unknown-pragmas" warning.

Compiling this code ...

#pragma comment(user,"This should depend on the command line options") #pragma GCC diagnostic warning "-Wunknown-pragmas" #pragma comment(user,"This should cause a warning") #pragma GCC diagnostic error "-Wunknown-pragmas" #pragma comment(user,"This should cause an error") #pragma GCC diagnostic ignored "-Wunknown-pragmas" #pragma comment(user,"This should be ignored") 

... produces either no warning/error (except that the linker complais about a missing main), or when using -Wall or just -Wunknown-pragmas it produces one warning for each of the comment pragmas.

The behaviour that I would have expected is that each comment should have caused exactly what the comment says.

I think I can back my expectation with the documentation:

At the moment only warnings (normally controlled by ‘-W...’) can be controlled, and not all of them. Use -fdiagnostics-show-option to determine which diagnostics are controllable and which option controls them.

The warnings I get show as

warning: ignoring #pragma comment [-Wunknown-pragmas] 

and as the part in brackets tells us,

  • this diagnostic is controllable
  • and the option -Wunknown-pragmas controls it

Hence my code should work.

So what am I doing wrong?


version info:

$ gcc --version gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609 
1

1 Answer 1

2

This is a long-standing missing feature in the GCC C++ front end:

Warnings generated by preprocessing cannot be controlled using programs in g++. Unlike the C front end, pragmas are processed only after the preprocessing phase in the C++ front end.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.