From patchwork Mon Jul 25 18:43:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 56315 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 56276383A304 for ; Mon, 25 Jul 2022 18:43:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56276383A304 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658774622; bh=Tolpl7qBFKeV0hgbhhPU5CIaad0nF0n0QLwQQ/Ta1iA=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ESlwsRmQGAOBzjO8lQEeGNGkspvdpuLPvNId4+jyyrVoJaDV8h7TmuFArretOcanz wmONgkr5TAZ2AQbDBb5CGZ3v0CglV5lNEZObAM4BUh7qluCqvsbU2992UCe60anwoS dDuaXVRwZ+W3D/VtDzKSCxTWjlJbOoNtz+6wh1pg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 1DD583858C53 for ; Mon, 25 Jul 2022 18:43:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1DD583858C53 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-547-UfxBBq1UPhulpTGY4Fr0rA-1; Mon, 25 Jul 2022 14:43:10 -0400 X-MC-Unique: UfxBBq1UPhulpTGY4Fr0rA-1 Received: by mail-qt1-f197.google.com with SMTP id h21-20020ac87775000000b0031f1f223ccaso4754427qtu.22 for ; Mon, 25 Jul 2022 11:43:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Tolpl7qBFKeV0hgbhhPU5CIaad0nF0n0QLwQQ/Ta1iA=; b=QIA5Rw6ZtDApWBJ99VulqCPQ3mnhdaBYFCICCB94SK30+dQ8iGXX/J96+hM2QRNX2O wVAsmmGgcaB7hZDcl26cMgIUSF5GMeExRgzVmvaXOqqx047K9AFRu3nRU0/D4FIhR6wG UokpllZU552yXvbGMeeIRtxzBR5p0w1y/dXnntpxiHw/wJXkudMZN7MkccNk8lWx/8Fs k2bDQMYscs374viylnEWhgce4fini6hb2wntkFzxhfLw9LMIMpjiRmmEYIKKW1WJfQ2z yhjERZTiQHfoJPGmafRjQJSfxx5tbw7z7sBlQx6URzR34cXiY0puvrp/WCYJjx8ISJ9N Afig== X-Gm-Message-State: AJIora/aTDYd0vbMCr534Z769AleErNHyOz0tFiXUkUgwPnG/ZUsHkiy X1ag03ZaWSzbg+g8b9NYDKrCeY0jKO129r/7+mGrBNu3YQxxApcIb26dZV63P2kcYoSVgYTBgYL 8e6kdDbmbQjmSCVjo6Q== X-Received: by 2002:a05:622a:188:b0:31f:1435:781d with SMTP id s8-20020a05622a018800b0031f1435781dmr11760915qtw.389.1658774590354; Mon, 25 Jul 2022 11:43:10 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vblqR60FXB6QbACyzFdMjEbnGLXw2bbxQyDa5lmwZhU2+Du5VT8PXqhslCwU1SWuHECtB8KQ== X-Received: by 2002:a05:622a:188:b0:31f:1435:781d with SMTP id s8-20020a05622a018800b0031f1435781dmr11760892qtw.389.1658774590092; Mon, 25 Jul 2022 11:43:10 -0700 (PDT) Received: from redhat.com ([2601:184:4780:4310::fc83]) by smtp.gmail.com with ESMTPSA id dt26-20020a05620a479a00b006b615cd8c13sm9781347qkb.106.2022.07.25.11.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 11:43:09 -0700 (PDT) Date: Mon, 25 Jul 2022 14:43:07 -0400 To: Jason Merrill Subject: [v2 PATCH] c++: ICE with erroneous template redeclaration [PR106311] Message-ID: References: <20220715152920.693196-1-polacek@redhat.com> <025f644d-be71-707b-22a3-cbdeb212517f@redhat.com> MIME-Version: 1.0 In-Reply-To: <025f644d-be71-707b-22a3-cbdeb212517f@redhat.com> User-Agent: Mutt/2.2.6 (2022-06-05) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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-Patchwork-Original-From: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Cc: GCC Patches Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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? -- >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 base-commit: 16aafa3194d4851a07cc204f56a5f0618f77e5d7 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" }