Blame SOURCES/gcc48-pr63567-1.patch

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