[Bug c/68119] New: GCC diagnostic push/pop interfere with control flow statements

2015-10-27 Thread jbrandmeyer at google dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68119

Bug ID: 68119
   Summary: GCC diagnostic push/pop interfere with control flow
statements
   Product: gcc
   Version: 4.9.3
Status: UNCONFIRMED
  Severity: critical
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: jbrandmeyer at google dot com
  Target Milestone: ---

Created attachment 36598
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36598&action=edit
Minimal test case

If the control-flow portion of a control-flow statement is wrapped with #pragma
GCC diagnostic push and pop, the subsequent brace-enclosed block is incorrectly
executed.  It is behaving as if the "diagnostic pop" inserts an additional
hidden semicolon.

In the attached minimal test case, test1 and test2 should both increment a by
1.  However, test2 actually increments a by 2.  Both "if" and "while"
statements are affected.

Observed in GCC 4.8.4 and 4.9.3.  G++ does not suffer from this issue. 
Optimization must be enabled to trigger this bug.  Even -Og is enough.  Despite
the use of -Wtype-limits in the example, other forms are also affected (ie,
-Wunused in that place also triggers this bug).


[Bug c/68119] GCC diagnostic push/pop interfere with control flow statements

2015-10-27 Thread jbrandmeyer at google dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68119

--- Comment #3 from Jonathan  ---
I can see how 6.10.6.1 grants GCC very broad latitude in how to treat its own
pragmas.  However, if the implementation is going to define this preprocessing
directive to behave as a statement, then it should at least be documented as
such in the manual.

For the C and C++ front-ends to operate differently with respect to this issue
is especially astonishing.