From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 37BF7385E021; Mon, 23 May 2022 08:43:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37BF7385E021 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/64758] [C++11] Give better error message when name of enum's base type cannot be resolved Date: Mon, 23 May 2022 08:43:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 May 2022 08:43:58 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D64758 --- Comment #4 from Jonathan Wakely --- For this code: enum class foo : bar { baz }; auto x =3D foo::baz; We give: e.C:1:6: warning: elaborated-type-specifier for a scoped enum must not use = the =E2=80=98class=E2=80=99 keyword 1 | enum class foo : bar { baz }; | ~~~~ ^~~~~ | ----- e.C:1:16: error: found =E2=80=98:=E2=80=99 in nested-name-specifier, expect= ed =E2=80=98::=E2=80=99 1 | enum class foo : bar { baz }; | ^ | :: e.C:1:12: error: =E2=80=98foo=E2=80=99 has not been declared 1 | enum class foo : bar { baz }; | ^~~ e.C:1:22: error: expected unqualified-id before =E2=80=98{=E2=80=99 token 1 | enum class foo : bar { baz }; | ^ e.C:2:10: error: =E2=80=98foo=E2=80=99 has not been declared 2 | auto x =3D foo::baz; | ^~~ Every one of these diagnostics is the result of bad error recovery from the initial problem. The warning is just nonsense. The first error is a bad recovery, we should = not assume it's a bested-name-specifier, we should assume it's an enum-base wit= h an undeclared type in the type-specifier-seq. The remaining errors are because= we failed to do anything useful with the bad enum definition. I suggest that we should notice that ": bar" is bad, give an error about "b= ar" being undeclared, and then act as though no enum-base was present for the r= est of the compilation. All the other diagnostics should vanish at that point. We won't complain about a bogus elaborared-type-specifier that isn't presen= t. We won't say 'foo' is undeclared. We won't complain about expecting an unqualified-id (when one is actually present, just not one we recognize), a= nd we won't complain about foo::baz being undeclared.=