Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< --
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. --- gcc/cp/pt.cc | 11 ++++++++--- gcc/testsuite/g++.dg/cpp1y/var-templ85.C | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ85.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 9c225c095c8..8bef2f8f6a2 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 00000000000..33c24e0c284 --- /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>; base-commit: f29f7f86935e29786bf9f976ec99d7639b381b14 -- 2.43.0