public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4797] c: Diagnose compound literals with function type [PR108043] Date: Mon, 19 Dec 2022 19:56:29 +0000 (GMT) [thread overview] Message-ID: <20221219195629.DFAAE3858D1E@sourceware.org> (raw) https://gcc.gnu.org/g:4e4620d8c796af482b57b94932618d1f9d9af9f7 commit r13-4797-g4e4620d8c796af482b57b94932618d1f9d9af9f7 Author: Jakub Jelinek <jakub@redhat.com> Date: Mon Dec 19 20:55:56 2022 +0100 c: Diagnose compound literals with function type [PR108043] Both C99 and latest C2X say that compound literal shall have an object type (complete object type in the latter case) or array of unknown bound, so complit with function type is invalid. When the initializer had to be non-empty for such case, we used to diagnose it as incorrect initializer, but with (fntype){} now allowed we just ICE on it. The following patch diagnoses that. 2022-12-19 Jakub Jelinek <jakub@redhat.com> PR c/108043 * c-parser.cc (c_parser_postfix_expression_after_paren_type): Diagnose compound literals with function type. * gcc.dg/pr108043.c: New test. * gcc.dg/c99-complit-2.c (foo): Adjust expected diagnostics for complit with function type. Diff: --- gcc/c/c-parser.cc | 5 +++++ gcc/testsuite/gcc.dg/c99-complit-2.c | 2 +- gcc/testsuite/gcc.dg/pr108043.c | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 1bbb39f9b08..7d6960fffbb 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 8120ce8d988..5e1b5be8e28 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 00000000000..0cc0700f30a --- /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" } */ +}
reply other threads:[~2022-12-19 19:56 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221219195629.DFAAE3858D1E@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).