public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8683] c++: pedwarn for empty unnamed enum in decl [PR67048] Date: Fri, 12 Aug 2022 08:11:10 +0000 (GMT) [thread overview] Message-ID: <20220812081110.14EB23858D28@sourceware.org> (raw) https://gcc.gnu.org/g:60fed79c1e9a968eaedf292b298d19c9475ad37a commit r12-8683-g60fed79c1e9a968eaedf292b298d19c9475ad37a Author: Marek Polacek <polacek@redhat.com> Date: Thu Apr 28 16:50:06 2022 -0400 c++: pedwarn for empty unnamed enum in decl [PR67048] [dcl.dcl]/5 says that enum { }; is ill-formed, and since r197742 we issue a pedwarn. However, the pedwarn also fires for enum { } x; which is well-formed. So only warn when {} is followed by a ;. This should be correct since you can't have "enum {}, <whatever>" -- that produces "expected unqualified-id before ',' token". PR c++/67048 gcc/cp/ChangeLog: * parser.cc (cp_parser_enum_specifier): Warn about empty unnamed enum only when it's followed by a semicolon. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/enum42.C: New test. (cherry picked from commit fd0d3e9121c5aa65150d242676be6bbdc8d4a92a) Diff: --- gcc/cp/parser.cc | 4 +++- gcc/testsuite/g++.dg/cpp0x/enum42.C | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 763df6f479b..5de1a80288e 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -21007,7 +21007,9 @@ cp_parser_enum_specifier (cp_parser* parser) /* If the next token is not '}', then there are some enumerators. */ else if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_BRACE)) { - if (is_unnamed && !scoped_enum_p) + if (is_unnamed && !scoped_enum_p + /* Don't warn for enum {} a; here. */ + && cp_lexer_nth_token_is (parser->lexer, 2, CPP_SEMICOLON)) pedwarn (type_start_token->location, OPT_Wpedantic, "ISO C++ forbids empty unnamed enum"); } diff --git a/gcc/testsuite/g++.dg/cpp0x/enum42.C b/gcc/testsuite/g++.dg/cpp0x/enum42.C new file mode 100644 index 00000000000..05b372a1947 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/enum42.C @@ -0,0 +1,7 @@ +// PR c++/67048 +// { dg-do compile { target c++11 } } +// { dg-options -Wpedantic } + +typedef enum {} X; +enum {} x; +enum {} y, z;
reply other threads:[~2022-08-12 8:11 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=20220812081110.14EB23858D28@sourceware.org \ --to=rguenth@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).