Message ID | Yt7kOzIEbjN3t1W5@redhat.com |
---|---|
State | New, archived |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp1817637pxt; Mon, 25 Jul 2022 11:43:57 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tMxH2/LWxXljxVxS74buHEEeHSlNfRGQsWNtueqey0eONjxQ+HP1NWVRh25MUXX41iNvOJ X-Received: by 2002:a17:907:75c6:b0:72b:496c:77c7 with SMTP id jl6-20020a17090775c600b0072b496c77c7mr11047498ejc.47.1658774637753; Mon, 25 Jul 2022 11:43:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658774637; cv=none; d=google.com; s=arc-20160816; b=M2Qn+XqNmjUI4IGbF3QjALPQotBa+3u4KZYeK+bAfwDHx2TV6N4TS9ArYJpqzbzApt LMrYyS36CSEQqvclVog5VxKDX1+jVTxd9VnyRfUj6mDr8WJU0nOQesTG1DQ70T3gQVa/ ouDi4rU8XJVZatQwsAQiP9+mrhEGEHZdPlP4BArW9nG+Thlt23YDAmySAhaDz2Tsu5kd SZOenZ3l8dXJOW/i91vz0JtMfOjsK16TlmmPOp5tsXl2DFkCGKeFdInhRxr+K7jPstjR gUFD/8dAIA5/LRyGdbgxmsxKmCrlwpaCFyTPOOjAJaI0ok4/qaYGTI+Eu+glPBCH1B38 tiyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:user-agent:in-reply-to:mime-version:references :message-id:subject:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=Tolpl7qBFKeV0hgbhhPU5CIaad0nF0n0QLwQQ/Ta1iA=; b=RllxtopLLlMTqu9twQY/QbE32jSmuvAx1Z0WG4KJM4ZNCF9zWJ/UwU3xKInantMcgs Yh6MDWTSPra/M52aa//Zg2oTlD/9NiV8vz6EQGgNzC68l/vAfeLEbYOMIIHxcP5iSc3D hA3noGkwh1/Vp2O4PQp9CrEmtVPKr0K5/ggSHhrPBN34j9Pr65auuOHNjaEEh+4alWPD f6d0zvCl69q7eQ4aflgUYNGb9JlRtE5Z1lRSYbVvM9xxeBvLOOhvRl6M0JuFeLmh+krp Xh+ACwWOLQd6neUwSk84Wq80Gc4ayeuhtFvTcA9NENLtD2wqvV47GEQf9/JutBFtui0j uqHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yzeTBtE0; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a11-20020a50858b000000b0043ba23f56a6si10484564edh.200.2022.07.25.11.43.57 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 11:43:57 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yzeTBtE0; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 698733858418 for <ouuuleilei@gmail.com>; Mon, 25 Jul 2022 18:43:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 698733858418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658774636; 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=yzeTBtE06PzoUnPUnbOLWoi1yeKMI8kUwtvz27GC4I8R9W808CImS8CFbz3tlfP0X pfycVwG+a8tvtV9x+s0Kkyo8A2zCz9xknDrCd9tDrFwmJrtEzQjnoODvEqbhXvcg/J S/P7NtsRJGjFeTVSxmxyEqjAYZah60so/Vy9F/aY= 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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org>; 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-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 <jason@redhat.com> Subject: [v2 PATCH] c++: ICE with erroneous template redeclaration [PR106311] Message-ID: <Yt7kOzIEbjN3t1W5@redhat.com> 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-Type: text/plain; charset=us-ascii 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Marek Polacek via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Marek Polacek <polacek@redhat.com> Cc: GCC Patches <gcc-patches@gcc.gnu.org> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1738433126584119719?= X-GMAIL-MSGID: =?utf-8?q?1739351274480522925?= |
Series |
[v2] c++: ICE with erroneous template redeclaration [PR106311]
|
|
Commit Message
Marek Polacek
July 25, 2022, 6:43 p.m. UTC
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 "<error node>" 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
Comments
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 "<error node>" 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 <typename, long> struct array; // { dg-error "template parameter" } > +template <typename, size_t X> struct array { }; // { dg-error "declared" } > > 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 <typename, long> struct array; // { dg-error "template parameter" } +template <typename, size_t X> struct array { }; // { dg-error "declared" }