From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id 919153858D28; Fri, 29 Apr 2022 19:08:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 919153858D28 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marek Polacek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-51] c++: pedwarn for empty unnamed enum in decl [PR67048] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 8d0fcf135857869f7cff36d29bc3527c482372a9 X-Git-Newrev: fd0d3e9121c5aa65150d242676be6bbdc8d4a92a Message-Id: <20220429190838.919153858D28@sourceware.org> Date: Fri, 29 Apr 2022 19:08:38 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Apr 2022 19:08:38 -0000 https://gcc.gnu.org/g:fd0d3e9121c5aa65150d242676be6bbdc8d4a92a commit r13-51-gfd0d3e9121c5aa65150d242676be6bbdc8d4a92a Author: Marek Polacek 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 {}, " -- 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. 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 ee69934c20f..a5cbb3e896f 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -21012,7 +21012,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;