Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why "pragma GCC diagnostic push" pop warning in GCC/C++?

Tags:

c++

pragma

#pragma GCC diagnostic push

it pop: warning: expected [error|warning|ignored] after â#pragma GCC diagnosticâ

Why? I use GCC in Linux.

I have one question, if I can't use pop/push, if the ignore only influence the compiled cpp, not influence other cpp? if some other include the cap, if influence it?

like image 448
jiafu Avatar asked May 15 '13 02:05

jiafu


People also ask

How do I turn off GCC warning?

-Wno-coverage-mismatch can be used to disable the warning or -Wno-error=coverage-mismatch can be used to disable the error. Disabling the error for this warning can result in poorly optimized code and is useful only in the case of very minor changes such as bug fixes to an existing code-base.

What is #pragma GCC diagnostic push?

#pragma GCC diagnostic push #pragma GCC diagnostic pop. Causes GCC to remember the state of the diagnostics as of each push , and restore to that point at each pop . If a pop has no matching push , the command-line options are restored.

Does GCC support Pragma message?

GCC supports several types of pragmas, primarily in order to compile code originally written for other compilers. Note that in general we do not recommend the use of pragmas; See Declaring Attributes of Functions, for further explanation.

What is werror?

-Werror= Make the specified warning into an error. The specifier for a warning is appended, for example -Werror=switch turns the warnings controlled by -Wswitch into errors.


1 Answers

#pragma GCC diagnostic push and #pragma GCC diagnostic pop were added in gcc 4.6. You're using an older version.

These pragmas are typically used in conjunction with other #pragma GCC diagnostic directives to suppress, turn on, or turn into an error specific warnings for a small section of your code only. If they're ignored, the changes to warning levels will apply to the rest of the source file rather than just until the next #pragma GCC diagnostic pop. This may not be a problem, or it may be the end of the world; you'll need to understand your code to know for sure.

Either way, you should probably update your compiler. You wouldn't compile C99 with a C89 compiler; don't compile code containing pragmas for gcc 4.6 with gcc 4.4.

like image 65
Cairnarvon Avatar answered Oct 12 '22 06:10

Cairnarvon