http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60875
Bug ID: 60875 Summary: `_Pragma("message \"foo\")"` doesn't work in expression contexts. Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: preprocessor Assignee: unassigned at gcc dot gnu.org Reporter: thakis at chromium dot org Actual: $ cat test.cc int main() { return _Pragma("message \"hello\"") 1234; } $ ~/gcc482prefix/bin/gcc -c test.cc -Wall test.cc: In function ‘int main()’: test.cc:2:1: error: ‘#pragma’ is not allowed here return _Pragma("message \"my warning\"") 1234; ^ test.cc:2:44: error: expected ‘;’ before numeric constant return _Pragma("message \"my warning\"") 1234; ^ test.cc:2:49: warning: statement has no effect [-Wunused-value] return _Pragma("message \"my warning\"") 1234; ^ Expected (which is what clang does, and what MSVS does with ` __pragma(message...`): Display the message instead. (clang's output: $ ../../../chrome/src/third_party/llvm-build/Release+Asserts/ bin/clang -c test.cc -Wall test.cc:2:10: warning: my warning [-W#pragma-messages] return _Pragma("message \"my warning\"") 1234; ^ <scratch space>:2:2: note: expanded from here message "my warning" ^ 1 warning generated. ) A silly workaround is to use _Pragma("message_workaround...), then gcc will warn like so: test.cc:2:10: warning: unknown pragma ignored [-Wunknown-pragmas] return _Pragma("message_workaround \"my warning\"") 1234; ^ It'd be nice if _Pragma(message...) could be used directly, instead of having to rely on -Wunknown-pragmas for this functionality. (The usecase we have for this in Chromium is that we want to make the compiler print a diagnostic every time some symbols are used, so we define the symbols as #define MY_SYMBOL _Pragma("message \"foo\"") SYMBOL This works fine in clang and MSVC, but for gcc we have to use a dummy pragma and rely on -Wunknown-pragmas.)