re PR c/53532 (function call ignored when called with argument of incompatible, undef...
authorJakub Jelinek <jakub@redhat.com>
Tue, 12 Jun 2012 21:16:20 +0000 (23:16 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 12 Jun 2012 21:16:20 +0000 (23:16 +0200)
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.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.

From-SVN: r188483

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wcxx-compat-8.c
gcc/testsuite/gcc.dg/c99-complit-2.c
gcc/testsuite/gcc.dg/noncompile/950825-1.c
gcc/testsuite/gcc.dg/pr51034.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr53196-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr53196-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr53532.c [new file with mode: 0644]

index 92bb3c296273b745b4793763f3bd264fda009d4f..8824983eb2a2f610e8715b566978ef40811e2bd1 100644 (file)
@@ -1,3 +1,11 @@
+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.
+
 2012-06-12  Uros Bizjak  <ubizjak@gmail.com>
 
        * config/ia64/sync.md (fetchop_name): Change ior attribute to "or".
index 1b51d219c587713eeb80872e1ab88d50f28ee313..86add1402b4ff64cbd6b6013759480432d716b90 100644 (file)
@@ -4637,7 +4637,10 @@ build_compound_literal (location_t loc, tree type, tree init, bool non_const)
     }
 
   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);
index 2f7f3f18abad02c0bd9ed4fa14913d2b4c2bbbb7..cdeb722d27b73ac98bc200d2d734f0997302dbdf 100644 (file)
@@ -1,3 +1,17 @@
+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.
+
 2012-06-12  Janis Johnson  <janisjo@codesourcery.com>
 
        * gcc.dg/torture/stackalign/stackalign.exp: Combine stack
index 7dad7a48dd456380e197c990904e953a52d246d1..f7e8c557914625d909e5aa52b4419488be2989d8 100644 (file)
@@ -63,3 +63,5 @@ f5 ()
 {
   return &((struct t8) { });  /* { dg-warning "invalid in C\[+\]\[+\]" } */
 }
+
+/* { dg-error "invalid use of undefined type" "" { target *-*-* } 64 } */
index faf44b2376e34e232e1f14cbded010cda26331ed..1285e7e0d2bf1b24da0651e2236ba350bbe708e1 100644 (file)
@@ -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 } */
 }
index 4f4c6fbb9e29f7980b8a4daaecd735791ef0879a..43dca2f103ebcae8169e97fdbcaf88db9ab849c8 100644 (file)
@@ -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" } */
 }
diff --git a/gcc/testsuite/gcc.dg/pr51034.c b/gcc/testsuite/gcc.dg/pr51034.c
new file mode 100644 (file)
index 0000000..c9b9c27
--- /dev/null
@@ -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" } */
+}
diff --git a/gcc/testsuite/gcc.dg/pr53196-1.c b/gcc/testsuite/gcc.dg/pr53196-1.c
new file mode 100644 (file)
index 0000000..b33e043
--- /dev/null
@@ -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;
+}
diff --git a/gcc/testsuite/gcc.dg/pr53196-2.c b/gcc/testsuite/gcc.dg/pr53196-2.c
new file mode 100644 (file)
index 0000000..efb6a82
--- /dev/null
@@ -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 } */
diff --git a/gcc/testsuite/gcc.dg/pr53532.c b/gcc/testsuite/gcc.dg/pr53532.c
new file mode 100644 (file)
index 0000000..9caea40
--- /dev/null
@@ -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;
+}