register_specialization complains about a specialization in a different
namespace from the main template; we shouldn't give that error about an
instantiation of a partial specialization. And we were about to
SET_DECL_IMPLICIT_INSTANTIATION anyway, so let's just do that before we
call register_specialization.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit a1ab0a6ef49dcb604c12058b9af7522e471bcc5b
Author: Jason Merrill <ja...@redhat.com>
Date: Wed May 20 16:53:57 2015 -0400
* pt.c (tsubst_decl) [VAR_DECL]: SET_DECL_IMPLICIT_INSTANTIATION
before register_specialization.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 60f3958..7555114 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -11407,9 +11407,9 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
processing here. */
DECL_EXTERNAL (r) = 1;
- register_specialization (r, gen_tmpl, argvec, false, hash);
DECL_TEMPLATE_INFO (r) = build_template_info (tmpl, argvec);
SET_DECL_IMPLICIT_INSTANTIATION (r);
+ register_specialization (r, gen_tmpl, argvec, false, hash);
}
else if (!cp_unevaluated_operand)
register_local_specialization (r, t);
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ27.C b/gcc/testsuite/g++.dg/cpp1y/var-templ27.C
new file mode 100644
index 0000000..da06b01
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/var-templ27.C
@@ -0,0 +1,9 @@
+// { dg-do compile { target c++14 } }
+
+namespace A
+{
+ template <class T> int I = 0;
+ template <class T> int I<T*> = 42;
+}
+
+int i = A::I<void*>;