From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 6A5CA3839C7D for ; Sun, 5 Jun 2022 10:09:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6A5CA3839C7D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=hXHn3+AFM3D6EY6HfLzbeCdIe+2F0pVtXLRkzgqiXXo=; b=J739i4YZ4JaV1FJsvDEz/6ZF6F mSn37ggCeNyjeQkZLWO/KxQHxH43Vrkp7JOAPjLDGk08NzCUKPLpJrfCgsEUS9EA/Tulbbbs33wn2 xrTli/VMwV/ZalqatB5zYptc+iIfxmFOK8ZzvcZtqBp4m2oz1UdVW6DtyLQ2PGVvnLn8B+pm+tcL4 cN4YKrJBuDvNgHsY4r1F4BCvvKgtYfPZhdlPn8ksUoCXFpbENQA+ksQzRJy92uNkphnVOv5IVI9my ZO7opfohxVTeD+QwVKO6t9ixmkj9W7Lm10XCQ7n4tI0dYtSn2msuA6C5KkzWxMT9/W9Yh3dB4gsRU HhxcsZ4Q==; Received: from host109-154-46-241.range109-154.btcentralplus.com ([109.154.46.241]:61804 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nxnCL-0007uA-Kq; Sun, 05 Jun 2022 06:09:29 -0400 From: "Roger Sayle" To: "'Jason Merrill'" , Subject: [C++ PATCH take #2] PR c++/96442: Improved error recovery in enumerations. Date: Sun, 5 Jun 2022 11:09:27 +0100 Message-ID: <003c01d878c4$58219a70$0864cf50$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_003D_01D878CC.B9E87370" X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adh4w51TY6gGCeqpQBa55EFjwrFvQg== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Jun 2022 10:09:32 -0000 This is a multipart message in MIME format. ------=_NextPart_000_003D_01D878CC.B9E87370 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Hi Jason, My apologies for the long delay, but I've finally got around to implementing your suggested improvements (implied by your review): https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591504.html of my patch for PR c++/96442: https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590716.html The "How does that happen?" is insightful and leads to a cleaner solution, setting ENUM_UNDERLYING_TYPE to integer_type_node when issuing an error, so that this invariant holds during the parser's error recovery. I've also moved the new testcase to the g++.dg/parse subdirectory as per your feedback on my previous ICE-on-invalid fixes. This patch has been tested on x86_64-pc-linunx-gnu with make bootstrap and make -k check with no new (unexpected) failures. Ok for mainline? 2022-06-05 Roger Sayle gcc/cp/ChangeLog PR c++/96442 * decl.cc (start_enum): When emitting a "must be integral" error, set ENUM_UNDERLYING_TYPE to integer_type_node, to avoid an ICE downstream in build_enumeration. gcc/testsuite/ChangeLog PR c++/96442 * g++.dg/parse/pr96442.C: New test cae. Thanks again, Roger -- > -----Original Message----- > From: Jason Merrill > Sent: 10 March 2022 05:06 > To: Roger Sayle ; gcc-patches@gcc.gnu.org > Subject: Re: [C++ PATCH] PR c++/96442: Another improved error recovery in > enumerations. > > On 2/22/22 08:02, Roger Sayle wrote: > > > > This patch resolves PR c++/96442, another ICE-after-error regression. > > In this case, invalid code attempts to use a non-integral type as the > > underlying type for an enumeration (a record_type in the example given > > in the bugzilla PR), for which the parser emits an error message but > > allows the inappropriate type to leak to downstream code. > > How does that happen? > > Would it help to change dependent_type_p in start_enum to > WILDCARD_TYPE_P? > > > The minimal > > safe fix is to double check that the enumeration's underlying type > > EUTYPE satisfies INTEGRAL_TYPE_P before calling int_fits_type_p in > > build_enumerator. This is a one line fix, but correcting indentation > > and storing a common subexpression in a variable makes the change look > > a little bigger. > > > > This patch has been tested on x86_64-pc-linunx-gnu with make bootstrap > > and make -k check with no new (unexpected) failures. Ok for mainline? > > > > > > 2022-02-22 Roger Sayle > > > > gcc/cp/ChangeLog > > PR c++/96442 > > * decl.cc (build_enumeration): Check ENUM_UNDERLYING_TYPE is > > INTEGRAL_TYPE_P before calling int_fits_type_p. > > > > gcc/testsuite/ChangeLog > > PR c++/96442 > > * g++.dg/pr96442.C: New test cae. > > > > > > Thanks in advance, > > Roger > > -- > > ------=_NextPart_000_003D_01D878CC.B9E87370 Content-Type: text/plain; name="patchcp3.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchcp3.txt" diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc=0A= index e0d397d..ca735d3 100644=0A= --- a/gcc/cp/decl.cc=0A= +++ b/gcc/cp/decl.cc=0A= @@ -16306,8 +16306,11 @@ start_enum (tree name, tree enumtype, tree = underlying_type,=0A= else if (dependent_type_p (underlying_type))=0A= ENUM_UNDERLYING_TYPE (enumtype) =3D underlying_type;=0A= else=0A= - error ("underlying type %qT of %qT must be an integral type", =0A= - underlying_type, enumtype);=0A= + {=0A= + error ("underlying type %qT of %qT must be an integral type", =0A= + underlying_type, enumtype);=0A= + ENUM_UNDERLYING_TYPE (enumtype) =3D integer_type_node;=0A= + }=0A= }=0A= =0A= /* If into a template class, the returned enum is always the first=0A= diff --git a/gcc/testsuite/g++.dg/parse/pr96442.C = b/gcc/testsuite/g++.dg/parse/pr96442.C=0A= new file mode 100644=0A= index 0000000..235bb11=0A= --- /dev/null=0A= +++ b/gcc/testsuite/g++.dg/parse/pr96442.C=0A= @@ -0,0 +1,6 @@=0A= +/* { dg-do compile } */=0A= +/* { dg-options "-O2" } */=0A= +enum struct a : struct {};=0A= +template enum class a : class c{};=0A= +enum struct a {b};=0A= +// { dg-excess-errors "" }=0A= ------=_NextPart_000_003D_01D878CC.B9E87370--