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).