diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 1bbb39f9b087..7d6960fffbb6 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -10924,6 +10924,11 @@ c_parser_postfix_expression_after_paren_type (c_parser *parser, error_at (type_loc, "compound literal has variable size"); type = error_mark_node; } + else if (TREE_CODE (type) == FUNCTION_TYPE) + { + error_at (type_loc, "compound literal has function type"); + type = error_mark_node; + } if (constexpr_p && type != error_mark_node) { tree type_no_array = strip_array_types (type); diff --git a/gcc/testsuite/gcc.dg/c99-complit-2.c b/gcc/testsuite/gcc.dg/c99-complit-2.c index 8120ce8d988e..5e1b5be8e282 100644 --- a/gcc/testsuite/gcc.dg/c99-complit-2.c +++ b/gcc/testsuite/gcc.dg/c99-complit-2.c @@ -23,7 +23,7 @@ foo (int a) /* { dg-error "init" "incomplete union type" { target *-*-* } .-1 } */ /* { dg-error "invalid use of undefined type" "" { target *-*-* } .-2 } */ (void (void)) { 0 }; /* { dg-bogus "warning" "warning in place of error" } */ - /* { dg-error "init" "function type" { target *-*-* } .-1 } */ + /* { dg-error "compound literal has function type" "function type" { target *-*-* } .-1 } */ (int [a]) { 1 }; /* { dg-bogus "warning" "warning in place of error" } */ /* { dg-error "init|variable" "VLA type" { target *-*-* } .-1 } */ /* Initializers must not attempt to initialize outside the object diff --git a/gcc/testsuite/gcc.dg/pr108043.c b/gcc/testsuite/gcc.dg/pr108043.c new file mode 100644 index 000000000000..0cc0700f30a0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108043.c @@ -0,0 +1,12 @@ +/* PR c/108043 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +typedef void F (void); + +void +foo (void) +{ + (F) {}; /* { dg-error "compound literal has function type" } */ + (F) { foo }; /* { dg-error "compound literal has function type" } */ +}