This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C PATCH] Diagnose compound literals with incomplete type (PR c/53532)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 2 Jun 2012 09:46:57 +0200
- Subject: [C PATCH] Diagnose compound literals with incomplete type (PR c/53532)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
As the testcase shows, we weren't diagnosing compound literals with
incomplete type at all. Fixed thusly, bootstrapped/regtested on
x86_64-linux and i686-linux, ok for trunk?
2012-06-02 Jakub Jelinek <jakub@redhat.com>
PR c/53532
* 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/c-decl.c.jj 2012-06-01 14:40:55.636420798 +0200
+++ gcc/c-decl.c 2012-06-01 17:52:04.587343492 +0200
@@ -4638,7 +4638,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/testsuite/gcc.dg/pr53532.c.jj 2012-06-01 17:52:04.603343388 +0200
+++ gcc/testsuite/gcc.dg/pr53532.c 2012-06-02 08:51:39.837776539 +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;
+}
--- gcc/testsuite/gcc.dg/c99-complit-2.c.jj 2008-09-05 12:54:36.000000000 +0200
+++ gcc/testsuite/gcc.dg/c99-complit-2.c 2012-06-02 08:50:49.984082757 +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/testsuite/gcc.dg/noncompile/950825-1.c.jj 2008-09-05 12:54:34.000000000 +0200
+++ gcc/testsuite/gcc.dg/noncompile/950825-1.c 2012-06-02 08:52:37.599406590 +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/testsuite/gcc.dg/Wcxx-compat-8.c.jj 2010-11-15 09:27:59.000000000 +0100
+++ gcc/testsuite/gcc.dg/Wcxx-compat-8.c 2012-06-02 08:49:10.516704705 +0200
@@ -63,3 +63,5 @@ f5 ()
{
return &((struct t8) { }); /* { dg-warning "invalid in C\[+\]\[+\]" } */
}
+
+/* { dg-error "invalid use of undefined type" "" { target *-*-* } 64 } */
Jakub