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 D0EF83857831 for ; Fri, 15 Jul 2022 15:29:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D0EF83857831 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-240-Le-iD1rHPOmchbl-DD3iug-1; Fri, 15 Jul 2022 11:29:24 -0400 X-MC-Unique: Le-iD1rHPOmchbl-DD3iug-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 884BA811E76 for ; Fri, 15 Jul 2022 15:29:24 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.17.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A9A218EB5; Fri, 15 Jul 2022 15:29:24 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: ICE with erroneous template redeclaration [PR106311] Date: Fri, 15 Jul 2022 11:29:20 -0400 Message-Id: <20220715152920.693196-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.5 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_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: Fri, 15 Jul 2022 15:29:34 -0000 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); 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: 23dd41c480fa9f06c33c1e6090bbae53869f85af -- 2.36.1