This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/71787] New: #pragma GCC diagnostic unexpectedly terminates a statement
- From: "gary at intrepid dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 07 Jul 2016 02:53:50 +0000
- Subject: [Bug c/71787] New: #pragma GCC diagnostic unexpectedly terminates a statement
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71787
Bug ID: 71787
Summary: #pragma GCC diagnostic unexpectedly terminates a
statement
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: gary at intrepid dot com
Target Milestone: ---
This bug may be related to PR41517.
Consider the following program:
#define NULL ((void *)0)
typedef enum {GET, SET} op_t;
extern void abort ();
void
get_set (op_t op,
int *ref,
int value __attribute__ ((unused)),
int *fetch)
{
int orig_value;
switch (op)
{
case GET:
orig_value = *ref;
break;
case SET:
if (fetch)
orig_value = *ref;
*ref = value;
break;
}
if (fetch)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
*fetch = orig_value;
#pragma GCC diagnostic pop
}
int
main ()
{
int v = 0;
int value;
get_set (GET, &v, 1, &value);
get_set (SET, &v, 10, &value);
get_set (SET, &v, 20, NULL);
}
When compiled and executed, it segfaults because the diagnostic push statement
is being handled as if it were a semi-colon.
If the sequence of statements above is changed to:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
if (fetch)
*fetch = orig_value;
#pragma GCC diagnostic pop
It executes as expected.
This is either a bug, or it would be helpful if the documentation is updated to
describe this behavior.