From d303aeafa9b46e06cd853696acb6345dff51a6b9 Mon Sep 17 00:00:00 2001 From: mpolacek Date: Sun, 19 Oct 2014 16:47:35 +0000 Subject: [PATCH] PR c/63567 * c-typeck.c (output_init_element): Allow initializing objects with static storage duration with compound literals even in C99 and add pedwarn for it. * gcc.dg/pr63567-3.c: New test. * gcc.dg/pr63567-4.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@216440 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/c/ChangeLog | 7 +++++++ gcc/c/c-typeck.c | 5 ++++- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/pr63567-3.c | 7 +++++++ gcc/testsuite/gcc.dg/pr63567-4.c | 7 +++++++ 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr63567-3.c create mode 100644 gcc/testsuite/gcc.dg/pr63567-4.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 35b8dcd..397bf28 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,10 @@ +2014-10-19 Marek Polacek + + PR c/63567 + * c-typeck.c (output_init_element): Allow initializing objects with + static storage duration with compound literals even in C99 and add + pedwarn for it. + 2014-10-17 Marek Polacek PR c/63567 diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 0dd3366..ee874da 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -8251,11 +8251,14 @@ output_init_element (location_t loc, tree value, tree origtype, value = array_to_pointer_conversion (input_location, value); if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR - && require_constant_value && !flag_isoc99 && pending) + && require_constant_value && pending) { /* As an extension, allow initializing objects with static storage duration with compound literals (which are then treated just as the brace enclosed list they contain). */ + if (flag_isoc99) + pedwarn_init (loc, OPT_Wpedantic, "initializer element is not " + "constant"); tree decl = COMPOUND_LITERAL_EXPR_DECL (value); value = DECL_INITIAL (decl); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 88b321b..b5c8fb7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2014-10-19 Marek Polacek + + PR c/63567 + * gcc.dg/pr63567-3.c: New test. + * gcc.dg/pr63567-4.c: New test. + 2014-10-19 Adhemerval Zanella * gcc.dg/atomic/c11-atomic-exec-5.c diff --git a/gcc/testsuite/gcc.dg/pr63567-3.c b/gcc/testsuite/gcc.dg/pr63567-3.c new file mode 100644 index 0000000..d626406 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr63567-3.c @@ -0,0 +1,7 @@ +/* PR c/63567 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +struct T { int i; }; +struct S { struct T t; }; +struct S s = { .t = { (int) { 1 } } }; diff --git a/gcc/testsuite/gcc.dg/pr63567-4.c b/gcc/testsuite/gcc.dg/pr63567-4.c new file mode 100644 index 0000000..0ca6c45 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr63567-4.c @@ -0,0 +1,7 @@ +/* PR c/63567 */ +/* { dg-do compile } */ +/* { dg-options "-Wpedantic" } */ + +struct T { int i; }; +struct S { struct T t; }; +struct S s = { .t = { (int) { 1 } } }; /* { dg-warning "initializer element is not constant" } */ -- 2.7.4