Ping: Re: pragma diagnostic push/pop

Manuel López-Ibáñez lopezibanez@gmail.com
Tue Jun 22 08:44:00 GMT 2010


On 22 June 2010 00:21, DJ Delorie <dj@redhat.com> wrote:
>
> Here you go, enjoy :-)
>
> Index: changes.html
> ===================================================================
> RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-4.6/changes.html,v
> retrieving revision 1.18
> diff -p -U3 -r1.18 changes.html
> --- changes.html        13 Jun 2010 12:44:28 -0000      1.18
> +++ changes.html        21 Jun 2010 22:20:12 -0000
> @@ -141,6 +141,14 @@
>  <h2>Documentation improvements</h2>
>
>  <h2>Other significant improvements</h2>
> +<ul>
> +  <li>The diagnostics pragmas have been expanded to be
> +  position-sensitive - a pragma in the middle of a source file only
> +  affects diagnostics that occur after it in the source.  The compiler
> +  can be told to save and restore the diagnostic state, so that
> +  diagnostics can (for example) be temporarily suppressed around a
> +  source line.</li>
> +</ul>
>


The <a href="http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas">diagnostics
pragmas</a> have been expanded to be position-sensitive: A pragma in
the middle of a source file only affects diagnostics that occur after
it in the source. New pragmas <code>#pragma GCC diagnostic
push/pop</code> tell the compiler to save and restore the state of
diagnostics, so that, for example, diagnostics can be temporarily
suppressed around a source line.

<pre>
/* Compiled with -O2 -Wuninitialized */
main()
{
 int a;
 int b;
 int c;
 int d;

#pragma GCC diagnostic error "-Wuninitialized"
 foo(a);                       /* "error: uninitialized" */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
 foo(b);
#pragma GCC diagnostic pop
 foo(c);                       /* "error :uninitialized" }*/
#pragma GCC diagnostic pop
 foo(d);                       /* "warning: uninitialized"
(command-line setting) */
}
</pre>

I may be wrong, but I am pretty sure this example does not actually
require -O2. We should warn for this at -O0 since at least GCC 4.4

Cheers,

Manuel.



More information about the Gcc-patches mailing list