From patchwork Fri Jul 15 15:29:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 19 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a98:d5ce:0:b0:178:cc93:bf7d with SMTP id g14csp437592eik; Fri, 15 Jul 2022 08:30:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sxXoAK9xSBYZf+s5Fow3mnFPE3ZQu1iDzNH1Z/vKWubzpiVVBH5HsbLwvMXN1Lm7+bNjYX X-Received: by 2002:a17:907:6818:b0:72b:5bac:c3a3 with SMTP id qz24-20020a170907681800b0072b5bacc3a3mr13836130ejc.139.1657899023430; Fri, 15 Jul 2022 08:30:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657899023; cv=none; d=google.com; s=arc-20160816; b=VvTJZXQ0a2qmDD3ZluMgDI3SSeqd9JGKGCpJgOptn3xeRKbilvXyFs1keBnkf44Wyf e4K0nuJe+KG6bFe9HeX5fMgXDrzXLUk6suqLPStkM68Wp/1Xf1oerRNrXjGkerVh5SHH dnPGPB7He6OLL6o8vkaZCnM6qAstyr8IoYDC41RMBNd4ej9Ngxl8DkZNLTexyCzWJJX8 xRszsSwzlBx1brZ2rFMTwzW5NneiDbKk9DCc7qqvjlibjcxvDQ89a7jBMeE++Aul47rs jIFZFfsSvvKCIrcwUGZISFdlUDaYqamDgrtgQEFR1+iWx5qczrosf4yvTRLUdOZHyb3/ f+Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=6vMEhQJwclwt8e0P+ZrP5YOL2FTS5+0jJfTP0+2Vt+s=; b=XmfJdl06gQDCnJ2U41h8UEMm2kV/lVrM7Q7yxJyQPj3tNh+gycp8irn57A+Dv6RHUW /fhgpCFbbK53dcScVIMcqgRorgui5gP0KqkeUbtQM9WIPJLt+gV2CiGGYOmq4mflVBlP GR+EzeyyeASy0BgH8DLToniCu5g+MUQfzaoriIHq9H1v96YeTmojMf9kxy/61wtA/XWJ Su6F8av219r3DX/NXgdbikoSZWeyMotds3kxlM30qQsoqJi8UnG1WTxc26ApKFctJ6L2 Ott5CHI02QeeVTTAPKs16KiBIpNPdOJoIzUWFhyRfDYxVgV49U7AwKaixWKOqPutDF2C oeWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="eIveD/GT"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id k1-20020a17090627c100b0072b3a7457fesi5759994ejc.846.2022.07.15.08.30.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 08:30:23 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="eIveD/GT"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 C5ABE385694C for ; Fri, 15 Jul 2022 15:30:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C5ABE385694C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1657899019; bh=6vMEhQJwclwt8e0P+ZrP5YOL2FTS5+0jJfTP0+2Vt+s=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=eIveD/GT+Ikg393OL0jPoC/oreXpBzlZYkcJs0gnR9+1PoDS677BPXasFY2cY95HW pV3aOb5M8QyMPFf/lchbKTvnrSn36to7o4P7sK+keyrLLCzkiTwANB+1CHfFLGhW27 i4GuNUG82DFqr3Q8FbDTZj98grA6WefvfJzVwImc= 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.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) 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 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-Patchwork-Original-From: Marek Polacek via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Marek Polacek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1738433126584119719?= X-GMAIL-MSGID: =?utf-8?q?1738433126584119719?= 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 base-commit: 23dd41c480fa9f06c33c1e6090bbae53869f85af 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" }