From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 675BE385842B for ; Tue, 26 Jul 2022 00:09:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 675BE385842B Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-608-evhDZ_UIPuuQESHKuFGI-A-1; Mon, 25 Jul 2022 20:09:15 -0400 X-MC-Unique: evhDZ_UIPuuQESHKuFGI-A-1 Received: by mail-qv1-f72.google.com with SMTP id l6-20020a0ce846000000b00473fbfc0e87so8476464qvo.19 for ; Mon, 25 Jul 2022 17:09:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=w9heJHhfqJWGCRuR3+FYBn7coAdPkna31LjWo0su6lU=; b=3kb2mBL/HmkB1MtfmnsHsDKjacVP7WCynbU7cJPSY43TLhNefY00MlMeNaqPkeqnim ktP/X+TSd8L6cRmZ7MQyTQZpp9BihdkuLcNTNN9hzaHzgxVxzaSOAezPIYVolDCSp0Vu n2CX1BCnz+qpnnPdJtKfO9LawKHPzPRquaZ5+eIlcBBurmL0Ux0x+wzsr+g7+4+lAvYK RLO9mUlmTyCDJNCYypx+1M+tUozE25eRlzP6su7RVlELvR3L/PhSNPjNAMLbvyZWY8KM Px4gXIfrdT/otvWNrECY/Vlc+VQPNAESgwuX58W1ghoInnaxvxX9hIcphYfmdxPybqE8 5cvQ== X-Gm-Message-State: AJIora/RtXPrdJcmf38g4KSIKCSXQEZ+brnoShI66mNjyx6PO1NxLW8E mcAMRtChKt4muaqzw3ky9vSUXsnZKorLPiBtm3klsbLhSmLdE+04deZo82e04bUKLwk7lmp6xH4 CDOoOQU1PWHGhV9oRag== X-Received: by 2002:ac8:5f85:0:b0:31f:22e8:bff9 with SMTP id j5-20020ac85f85000000b0031f22e8bff9mr12278364qta.196.1658794154334; Mon, 25 Jul 2022 17:09:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1svTmvV0DStNPWUBeN97Yux6P14utwLUg2OMH0JNJajU84CrUyV+4sSmMPjDOmxeWsCpAdpJQ== X-Received: by 2002:ac8:5f85:0:b0:31f:22e8:bff9 with SMTP id j5-20020ac85f85000000b0031f22e8bff9mr12278349qta.196.1658794153978; Mon, 25 Jul 2022 17:09:13 -0700 (PDT) Received: from [192.168.1.100] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id dm53-20020a05620a1d7500b006af0ce13499sm10257466qkb.115.2022.07.25.17.09.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Jul 2022 17:09:13 -0700 (PDT) Message-ID: <604b7c77-a525-d58e-5afa-ef1124fd4438@redhat.com> Date: Mon, 25 Jul 2022 20:09:12 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [v2 PATCH] c++: ICE with erroneous template redeclaration [PR106311] To: Marek Polacek Cc: GCC Patches References: <20220715152920.693196-1-polacek@redhat.com> <025f644d-be71-707b-22a3-cbdeb212517f@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP 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: Tue, 26 Jul 2022 00:09:17 -0000 On 7/25/22 14:43, Marek Polacek wrote: > On Fri, Jul 22, 2022 at 05:21:58PM -0400, Jason Merrill wrote: >> On 7/15/22 11:29, Marek Polacek wrote: >>> Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens >>> to be error_mark_node in this ill-formed test. I kept running into this >>> while reducing code, so it'd be good to have it fixed. >>> >>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? >>> >>> PR c++/106311 >>> >>> gcc/cp/ChangeLog: >>> >>> * pt.cc (redeclare_class_template): Check DECL_P before accessing >>> DECL_SOURCE_LOCATION. >>> >>> gcc/testsuite/ChangeLog: >>> >>> * g++.dg/template/redecl5.C: New test. >>> --- >>> gcc/cp/pt.cc | 3 ++- >>> gcc/testsuite/g++.dg/template/redecl5.C | 5 +++++ >>> 2 files changed, 7 insertions(+), 1 deletion(-) >>> create mode 100644 gcc/testsuite/g++.dg/template/redecl5.C >>> >>> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc >>> index 718dfa5bfa8..0a294e91a79 100644 >>> --- a/gcc/cp/pt.cc >>> +++ b/gcc/cp/pt.cc >>> @@ -6377,7 +6377,8 @@ redeclare_class_template (tree type, tree parms, tree cons) >>> { >>> auto_diagnostic_group d; >>> error ("template parameter %q+#D", tmpl_parm); >>> - inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm); >>> + inform (DECL_P (parm) ? DECL_SOURCE_LOCATION (parm) : input_location, >>> + "redeclared here as %q#D", parm); >> >> If we're checking DECL_P, probably we also should avoid passing it to %q#D >> if it's false? > > Right, I suppose printing "" isn't all that helpful. How about > this? > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? OK. > -- >8 -- > Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens > to be error_mark_node in this ill-formed test. I kept running into this > while reducing code, so it'd be good to have it fixed. > > PR c++/106311 > > gcc/cp/ChangeLog: > > * pt.cc (redeclare_class_template): Check DECL_P before accessing > DECL_SOURCE_LOCATION. > > gcc/testsuite/ChangeLog: > > * g++.dg/template/redecl5.C: New test. > --- > gcc/cp/pt.cc | 5 ++++- > gcc/testsuite/g++.dg/template/redecl5.C | 5 +++++ > 2 files changed, 9 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/template/redecl5.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index c415db304c9..6c581fe0fb7 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -6377,7 +6377,10 @@ redeclare_class_template (tree type, tree parms, tree cons) > { > auto_diagnostic_group d; > error ("template parameter %q+#D", tmpl_parm); > - inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm); > + if (DECL_P (parm)) > + inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm); > + else > + inform (input_location, "redeclared here"); > return false; > } > > diff --git a/gcc/testsuite/g++.dg/template/redecl5.C b/gcc/testsuite/g++.dg/template/redecl5.C > new file mode 100644 > index 00000000000..fb2d698e6bc > --- /dev/null > +++ b/gcc/testsuite/g++.dg/template/redecl5.C > @@ -0,0 +1,5 @@ > +// PR c++/106311 > +// { dg-do compile } > + > +template struct array; // { dg-error "template parameter" } > +template struct array { }; // { dg-error "declared" } > > base-commit: 16aafa3194d4851a07cc204f56a5f0618f77e5d7