[backport from gcc-4.8/trunk r188483 <mikpe@it.uu.se>]

gcc/

2012-06-12  Jakub Jelinek  <jakub@redhat.com>

	PR c/53532
	PR c/51034
	PR c/53196
	* c-decl.c (build_compound_literal): Call c_incomplete_type_error
	if type isn't complete.

gcc/testsuite/

2012-06-12  Jakub Jelinek  <jakub@redhat.com>

	PR c/53532
	PR c/51034
	PR c/53196
	* gcc.dg/pr53532.c: New test.
	* gcc.dg/c99-complit-2.c: Add two new dg-error directives,
	adjust line numbers.
	* gcc.dg/noncompile/950825-1.c: Expect incomplete type error message.
	* gcc.dg/Wcxx-compat-8.c: Likewise.
	* gcc.dg/pr51034.c: New test.
	* gcc.dg/pr53196-1.c: New test.
	* gcc.dg/pr53196-2.c: New test.

--- gcc-4.6.3/gcc/c-decl.c.~1~	2012-02-23 18:38:13.000000000 +0100
+++ gcc-4.6.3/gcc/c-decl.c	2012-09-09 12:00:25.000000000 +0200
@@ -4573,7 +4573,10 @@ build_compound_literal (location_t loc, 
     }
 
   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
-    return error_mark_node;
+    {
+      c_incomplete_type_error (NULL_TREE, type);
+      return error_mark_node;
+    }
 
   stmt = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
   complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt);
--- gcc-4.6.3/gcc/testsuite/gcc.dg/Wcxx-compat-8.c.~1~	2010-11-13 10:52:00.000000000 +0100
+++ gcc-4.6.3/gcc/testsuite/gcc.dg/Wcxx-compat-8.c	2012-09-09 12:00:25.000000000 +0200
@@ -63,3 +63,5 @@ f5 ()
 {
   return &((struct t8) { });  /* { dg-warning "invalid in C\[+\]\[+\]" } */
 }
+
+/* { dg-error "invalid use of undefined type" "" { target *-*-* } 64 } */
--- gcc-4.6.3/gcc/testsuite/gcc.dg/c99-complit-2.c.~1~	2001-12-04 23:55:40.000000000 +0100
+++ gcc-4.6.3/gcc/testsuite/gcc.dg/c99-complit-2.c	2012-09-09 12:00:25.000000000 +0200
@@ -18,45 +18,47 @@ foo (int a)
   /* { dg-error "init" "void type" { target *-*-* } 17 } */
   &(struct si) { 1 }; /* { dg-bogus "warning" "warning in place of error" } */
   /* { dg-error "init" "incomplete struct type" { target *-*-* } 19 } */
+  /* { dg-error "invalid use of undefined type" "" { target *-*-* } 19 } */
   &(union ui) { 1 }; /* { dg-bogus "warning" "warning in place of error" } */
-  /* { dg-error "init" "incomplete union type" { target *-*-* } 21 } */
+  /* { dg-error "init" "incomplete union type" { target *-*-* } 22 } */
+  /* { dg-error "invalid use of undefined type" "" { target *-*-* } 22 } */
   (void (void)) { 0 }; /* { dg-bogus "warning" "warning in place of error" } */
-  /* { dg-error "init" "function type" { target *-*-* } 23 } */
+  /* { dg-error "init" "function type" { target *-*-* } 25 } */
   (int [a]) { 1 }; /* { dg-bogus "warning" "warning in place of error" } */
-  /* { dg-error "init|variable" "VLA type" { target *-*-* } 25 } */
+  /* { dg-error "init|variable" "VLA type" { target *-*-* } 27 } */
   /* Initializers must not attempt to initialize outside the object
      declared.  */
   (int [1]) { [1] = 2 }; /* { dg-bogus "warning" "warning in place of error" } */
-  /* { dg-error "init" "value outside array" { target *-*-* } 29 } */
-  (int [1]) { [-1] = 2 }; /* { dg-bogus "warning" "warning in place of error" } */
   /* { dg-error "init" "value outside array" { target *-*-* } 31 } */
-  (int [1]) { 0, 1 }; /* { dg-bogus "warning" "warning in place of error" } */
+  (int [1]) { [-1] = 2 }; /* { dg-bogus "warning" "warning in place of error" } */
   /* { dg-error "init" "value outside array" { target *-*-* } 33 } */
+  (int [1]) { 0, 1 }; /* { dg-bogus "warning" "warning in place of error" } */
+  /* { dg-error "init" "value outside array" { target *-*-* } 35 } */
 }
 
 int z;
 
 /* Outside a function, initializers must be constant.  */
 struct s *s0 = &(struct s) { 0, z }; /* { dg-bogus "warning" "warning in place of error" } */
-/* { dg-error "init" "non-const" { target *-*-* } 40 } */
-int sz = sizeof((struct s) { 0, z }); /* { dg-bogus "warning" "warning in place of error" } */
 /* { dg-error "init" "non-const" { target *-*-* } 42 } */
+int sz = sizeof((struct s) { 0, z }); /* { dg-bogus "warning" "warning in place of error" } */
+/* { dg-error "init" "non-const" { target *-*-* } 44 } */
 
 /* Compound literals aren't themselves constant expressions.  */
 int x = (int) { 0 }; /* { dg-bogus "warning" "warning in place of error" } */
-/* { dg-error "init" "non-const" { target *-*-* } 46 } */
+/* { dg-error "init" "non-const" { target *-*-* } 48 } */
 
 /* Nor are they suitable structure or union initializers
    outside a function.  */
 struct s s1 = (struct s) { 0, 1 }; /* { dg-bogus "warning" "warning in place of error" } */
-/* { dg-error "init" "struct bad init" { target *-*-* } 51 } */
+/* { dg-error "init" "struct bad init" { target *-*-* } 53 } */
 union u u1 = (union u) { 0 }; /* { dg-bogus "warning" "warning in place of error" } */
-/* { dg-error "init" "union bad init" { target *-*-* } 53 } */
+/* { dg-error "init" "union bad init" { target *-*-* } 55 } */
 
 /* They aren't suitable for array initializers, either inside or outside
    a function.  */
 int y[2] = (int [2]) { 0, 1 }; /* { dg-bogus "warning" "warning in place of error" } */
-/* { dg-error "init" "array bad init" { target *-*-* } 58 } */
+/* { dg-error "init" "array bad init" { target *-*-* } 60 } */
 
 void
 bar (void)
@@ -64,5 +66,5 @@ bar (void)
   struct s s2 = (struct s) { 0, 1 };
   union u u2 = (union u) { 0 };
   int z[2] = (int [2]) { 0, 1 }; /* { dg-bogus "warning" "warning in place of error" } */
-  /* { dg-error "init" "array bad init" { target *-*-* } 66 } */
+  /* { dg-error "init" "array bad init" { target *-*-* } 68 } */
 }
--- gcc-4.6.3/gcc/testsuite/gcc.dg/noncompile/950825-1.c.~1~	2000-06-29 21:55:26.000000000 +0200
+++ gcc-4.6.3/gcc/testsuite/gcc.dg/noncompile/950825-1.c	2012-09-09 12:00:25.000000000 +0200
@@ -1,4 +1,4 @@
 main()
 {
-return (struct x) {{y: 0}};   /* { dg-error "extra|near|excess|incompatible" } */
+return (struct x) {{y: 0}};   /* { dg-error "extra|near|excess|incompatible|invalid" } */
 }
--- gcc-4.6.3/gcc/testsuite/gcc.dg/pr51034.c.~1~	1970-01-01 01:00:00.000000000 +0100
+++ gcc-4.6.3/gcc/testsuite/gcc.dg/pr51034.c	2012-09-09 12:00:25.000000000 +0200
@@ -0,0 +1,14 @@
+/* PR c/51034 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+struct S;
+
+int
+main ()
+{
+  struct R { typeof (((struct W) {})) x; } r;	/* { dg-error "invalid use of undefined type" } */
+  struct S { typeof (((struct S) {})) x; } s;	/* { dg-error "invalid use of undefined type" } */
+  struct T { int x[sizeof ((struct T) {})]; } t;/* { dg-error "invalid use of undefined type" } */
+  struct U { int x[sizeof((struct V){})];} u;	/* { dg-error "invalid use of undefined type" } */
+}
--- gcc-4.6.3/gcc/testsuite/gcc.dg/pr53196-1.c.~1~	1970-01-01 01:00:00.000000000 +0100
+++ gcc-4.6.3/gcc/testsuite/gcc.dg/pr53196-1.c	2012-09-09 12:00:25.000000000 +0200
@@ -0,0 +1,14 @@
+/* PR c/53196 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+extern int printf (const char *, ...);
+struct foo { int i; };
+
+int
+main ()
+{
+  struct foo f = (struct foo_typo) { };	/* { dg-error "invalid use of undefined type" } */
+  printf ("%d\n", f.i);
+  return 0;
+}
--- gcc-4.6.3/gcc/testsuite/gcc.dg/pr53196-2.c.~1~	1970-01-01 01:00:00.000000000 +0100
+++ gcc-4.6.3/gcc/testsuite/gcc.dg/pr53196-2.c	2012-09-09 12:00:25.000000000 +0200
@@ -0,0 +1,16 @@
+/* PR c/53196 */
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -pedantic-errors" } */
+
+extern int printf (const char *, ...);
+struct foo { int i; };
+
+int
+main ()
+{
+  struct foo f = (struct foo_typo) { };	/* { dg-error "invalid use of undefined type" } */
+  printf ("%d\n", f.i);
+  return 0;
+}
+
+/* { dg-error "ISO C forbids empty initializer braces" "" { target *-*-* } 11 } */
--- gcc-4.6.3/gcc/testsuite/gcc.dg/pr53532.c.~1~	1970-01-01 01:00:00.000000000 +0100
+++ gcc-4.6.3/gcc/testsuite/gcc.dg/pr53532.c	2012-09-09 12:00:25.000000000 +0200
@@ -0,0 +1,13 @@
+/* PR c/53532 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct S {};
+extern int foo (struct S);
+
+int
+main ()
+{
+  foo ((struct T) {});	/* { dg-error "invalid use of undefined type" } */
+  return 0;
+}
