re PR c/63567 (Linux kernel build error due to non-static initializers)

PR c/63567
	* c-typeck.c (digest_init): Allow initializing objects with static
	storage duration with compound literals even in C99 and add pedwarn
	for it.

	* gcc.dg/pr61096-1.c: Change dg-error into dg-warning.
	* gcc.dg/pr63567-1.c: New test.
	* gcc.dg/pr63567-2.c: New test.

From-SVN: r216416
This commit is contained in:
Marek Polacek 2014-10-17 21:02:54 +00:00 committed by Marek Polacek
parent d83fa499b9
commit 7278465e24
6 changed files with 38 additions and 2 deletions

View File

@ -1,3 +1,10 @@
2014-10-17 Marek Polacek <polacek@redhat.com>
PR c/63567
* c-typeck.c (digest_init): Allow initializing objects with static
storage duration with compound literals even in C99 and add pedwarn
for it.
2014-10-17 Marek Polacek <polacek@redhat.com>
PR c/63543

View File

@ -6683,13 +6683,15 @@ digest_init (location_t init_loc, tree type, tree init, tree origtype,
inside_init = convert (type, inside_init);
if (require_constant
&& (code == VECTOR_TYPE || !flag_isoc99)
&& TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
{
/* 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). Also allow this for
vectors, as we can only assign them with compound literals. */
if (flag_isoc99 && code != VECTOR_TYPE)
pedwarn_init (init_loc, OPT_Wpedantic, "initializer element "
"is not constant");
tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
inside_init = DECL_INITIAL (decl);
}

View File

@ -1,3 +1,10 @@
2014-10-17 Marek Polacek <polacek@redhat.com>
PR c/63567
* gcc.dg/pr61096-1.c: Change dg-error into dg-warning.
* gcc.dg/pr63567-1.c: New test.
* gcc.dg/pr63567-2.c: New test.
2014-10-17 Marek Polacek <polacek@redhat.com>
PR c/63543

View File

@ -23,7 +23,7 @@ char w1[] = L"foo"; /* { dg-error "13:char-array initialized from wide string" }
__WCHAR_TYPE__ w2[] = "foo"; /* { dg-error "23:wide character array initialized from non-wide string" } */
__WCHAR_TYPE__ w3[] = U"foo"; /* { dg-error "23:wide character array initialized from incompatible wide string" } */
schar a1[] = "foo"; /* { dg-error "14:array of inappropriate type initialized from string constant" } */
int a2[] = (int[]) { 1 }; /* { dg-error "12:array initialized from non-constant array expression" } */
int a2[] = (int[]) { 1 }; /* { dg-warning "12:initializer element is not constant" } */
int a3 = e; /* { dg-error "10:initializer element is not constant" } */
int a4 = (e, 1); /* { dg-error "10:initializer element is not constant" } */

View File

@ -0,0 +1,10 @@
/* PR c/63567 */
/* { dg-do compile } */
/* { dg-options "" } */
/* Allow initializing objects with static storage duration with
compound literals even. This is being used in Linux kernel. */
struct T { int i; };
struct S { struct T t; };
static struct S s = (struct S) { .t = { 42 } };

View File

@ -0,0 +1,10 @@
/* PR c/63567 */
/* { dg-do compile } */
/* { dg-options "-pedantic" } */
/* Allow initializing objects with static storage duration with
compound literals. This is being used in Linux kernel. */
struct T { int i; };
struct S { struct T t; };
static struct S s = (struct S) { .t = { 42 } }; /* { dg-warning "initializer element is not constant" } */