public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-8960] c++: variable partial spec redeclaration [PR113612]
Date: Tue, 13 Feb 2024 16:15:45 +0000 (GMT)	[thread overview]
Message-ID: <20240213161545.507C7385828B@sourceware.org> (raw)

https://gcc.gnu.org/g:19ac327de421fe05916e234e3450e6e1cc5c935c

commit r14-8960-g19ac327de421fe05916e234e3450e6e1cc5c935c
Author: Jason Merrill <jason@redhat.com>
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.

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 475f2181cc49..2803824d11e1 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -5417,9 +5417,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 <typename T> T t;
+template <typename T> extern T *t<T *>;
+template <typename T> T *t<T *> = t<int>;

                 reply	other threads:[~2024-02-13 16:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240213161545.507C7385828B@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).