diff options
author | Jakub Jelinek <jakub@redhat.com> | 2012-06-12 23:16:20 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2012-06-12 23:16:20 +0200 |
commit | cce5086157debf5d546591cc8f48a4dd95fd108b (patch) | |
tree | e993739bf8bc3a9a389b46900f9bbbceaa67308b | |
parent | 9690ac05c92a154b5d2ca7078d3bf6f4c7eb6c57 (diff) | |
download | gcc-cce5086157debf5d546591cc8f48a4dd95fd108b.zip gcc-cce5086157debf5d546591cc8f48a4dd95fd108b.tar.gz gcc-cce5086157debf5d546591cc8f48a4dd95fd108b.tar.bz2 |
re PR c/53532 (function call ignored when called with argument of incompatible, undefined structure)
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
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c-decl.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wcxx-compat-8.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c99-complit-2.c | 28 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/noncompile/950825-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr51034.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr53196-1.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr53196-2.c | 16 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr53532.c | 13 |
10 files changed, 101 insertions, 15 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 92bb3c2..8824983 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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". diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 1b51d21..86add14 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2f7f3f1..cdeb722 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 diff --git a/gcc/testsuite/gcc.dg/Wcxx-compat-8.c b/gcc/testsuite/gcc.dg/Wcxx-compat-8.c index 7dad7a4..f7e8c55 100644 --- a/gcc/testsuite/gcc.dg/Wcxx-compat-8.c +++ b/gcc/testsuite/gcc.dg/Wcxx-compat-8.c @@ -63,3 +63,5 @@ f5 () { return &((struct t8) { }); /* { dg-warning "invalid in C\[+\]\[+\]" } */ } + +/* { dg-error "invalid use of undefined type" "" { target *-*-* } 64 } */ diff --git a/gcc/testsuite/gcc.dg/c99-complit-2.c b/gcc/testsuite/gcc.dg/c99-complit-2.c index faf44b2..1285e7e 100644 --- a/gcc/testsuite/gcc.dg/c99-complit-2.c +++ b/gcc/testsuite/gcc.dg/c99-complit-2.c @@ -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 } */ } diff --git a/gcc/testsuite/gcc.dg/noncompile/950825-1.c b/gcc/testsuite/gcc.dg/noncompile/950825-1.c index 4f4c6fb..43dca2f 100644 --- a/gcc/testsuite/gcc.dg/noncompile/950825-1.c +++ b/gcc/testsuite/gcc.dg/noncompile/950825-1.c @@ -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 index 0000000..c9b9c27 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr51034.c @@ -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 index 0000000..b33e043 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr53196-1.c @@ -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 index 0000000..efb6a82 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr53196-2.c @@ -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 index 0000000..9caea40 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr53532.c @@ -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; +} |