From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 6B9BA3858015; Tue, 13 Feb 2024 16:16:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B9BA3858015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707841005; bh=HGm6J4eY9Rzz2PE+339CAODVOxWhapZ077X1fRhsuE0=; h=From:To:Subject:Date:From; b=XCX80dmdMa+CJPma67jSCEVZnEm3LkZVx/vsBzRhE83YQWtvgMSyEn9FDdljbxqfh 2oH8lRtQ+vKGSnDDUqdlFZ+s0A7hFEO3unKKyVnO4AJ0QnFsRwSMegg72ezB63UUH2 SXuGlXOz89h+4jA1WiX0fh91TUitiCNPpusyIWHM= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-8324] c++: variable partial spec redeclaration [PR113612] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 8a93dc34e90cd8e2bb073f8fd48f671aea62d965 X-Git-Newrev: ef7738d2d0ee0103946e5243aa7e5c8ad2fb0c6d Message-Id: <20240213161645.6B9BA3858015@sourceware.org> Date: Tue, 13 Feb 2024 16:16:45 +0000 (GMT) List-Id: https://gcc.gnu.org/g:ef7738d2d0ee0103946e5243aa7e5c8ad2fb0c6d commit r13-8324-gef7738d2d0ee0103946e5243aa7e5c8ad2fb0c6d Author: Jason Merrill Date: Mon Feb 12 21:00:53 2024 -0500 c++: variable partial spec redeclaration [PR113612] If register_specialization finds a previous declaration and throws the new one away, we shouldn't still add the new one to DECL_TEMPLATE_SPECIALIZATIONS. PR c++/113612 gcc/cp/ChangeLog: * pt.cc (process_partial_specialization): Return early on redeclaration. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/var-templ85.C: New test. (cherry picked from commit 19ac327de421fe05916e234e3450e6e1cc5c935c) Diff: --- gcc/cp/pt.cc | 11 ++++++++--- gcc/testsuite/g++.dg/cpp1y/var-templ85.C | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 98974ba57549..f5e6541fd0f0 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -5409,9 +5409,14 @@ process_partial_specialization (tree decl) } if (VAR_P (decl)) - /* We didn't register this in check_explicit_specialization so we could - wait until the constraints were set. */ - decl = register_specialization (decl, maintmpl, specargs, false, 0); + { + /* We didn't register this in check_explicit_specialization so we could + wait until the constraints were set. */ + tree reg = register_specialization (decl, maintmpl, specargs, false, 0); + if (reg != decl) + /* Redeclaration. */ + return reg; + } else associate_classtype_constraints (type); diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ85.C b/gcc/testsuite/g++.dg/cpp1y/var-templ85.C new file mode 100644 index 000000000000..33c24e0c2844 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ85.C @@ -0,0 +1,6 @@ +// PR c++/113612 +// { dg-do compile { target c++14 } } + +template T t; +template extern T *t; +template T *t = t;