fdda51
2014-10-17  Marek Polacek  <polacek@redhat.com>
fdda51
fdda51
	PR c/63567
fdda51
	* c-typeck.c (digest_init): Allow initializing objects with static
fdda51
	storage duration with compound literals even in C99 and add pedwarn
fdda51
	for it.
fdda51
fdda51
--- gcc/c/c-typeck.c
fdda51
+++ gcc/c/c-typeck.c
fdda51
@@ -6683,13 +6683,15 @@ digest_init (location_t init_loc, tree type, tree init, tree origtype,
fdda51
 	inside_init = convert (type, inside_init);
fdda51
 
fdda51
       if (require_constant
fdda51
-	  && (code == VECTOR_TYPE || !flag_isoc99)
fdda51
 	  && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
fdda51
 	{
fdda51
 	  /* As an extension, allow initializing objects with static storage
fdda51
 	     duration with compound literals (which are then treated just as
fdda51
 	     the brace enclosed list they contain).  Also allow this for
fdda51
 	     vectors, as we can only assign them with compound literals.  */
fdda51
+	  if (flag_isoc99 && code != VECTOR_TYPE)
fdda51
+	    pedwarn_init (init_loc, OPT_Wpedantic, "initializer element "
fdda51
+			  "is not constant");
fdda51
 	  tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
fdda51
 	  inside_init = DECL_INITIAL (decl);
fdda51
 	}
fdda51
--- /dev/null
fdda51
+++ gcc/testsuite/gcc.dg/pr63567-1.c
fdda51
@@ -0,0 +1,10 @@
fdda51
+/* PR c/63567 */
fdda51
+/* { dg-do compile } */
fdda51
+/* { dg-options "" } */
fdda51
+
fdda51
+/* Allow initializing objects with static storage duration with
fdda51
+   compound literals even.  This is being used in Linux kernel.  */
fdda51
+
fdda51
+struct T { int i; };
fdda51
+struct S { struct T t; };
fdda51
+static struct S s = (struct S) { .t = { 42 } };
fdda51
--- /dev/null
fdda51
+++ gcc/testsuite/gcc.dg/pr63567-2.c
fdda51
@@ -0,0 +1,10 @@
fdda51
+/* PR c/63567 */
fdda51
+/* { dg-do compile } */
fdda51
+/* { dg-options "-pedantic -std=gnu99" } */
fdda51
+
fdda51
+/* Allow initializing objects with static storage duration with
fdda51
+   compound literals.  This is being used in Linux kernel.  */
fdda51
+
fdda51
+struct T { int i; };
fdda51
+struct S { struct T t; };
fdda51
+static struct S s = (struct S) { .t = { 42 } }; /* { dg-warning "initializer element is not constant" } */