pt.c (check_explicit_specialization): Check the namespace after we choose a template.
authorJason Merrill <jason@redhat.com>
Thu, 12 Nov 2015 20:37:46 +0000 (15:37 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 12 Nov 2015 20:37:46 +0000 (15:37 -0500)
* pt.c (check_explicit_specialization): Check the namespace after
we choose a template.

From-SVN: r230271

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/template/explicit-instantiation4.C [new file with mode: 0644]

index d1bf1219e00f10b517d5712e3b8b3192c333ff77..9a02de26c1b9a0bdc2ca7d98effb0a6cd4102618 100644 (file)
@@ -1,3 +1,8 @@
+2015-11-12  Jason Merrill  <jason@redhat.com>
+
+       * pt.c (check_explicit_specialization): Check the namespace after
+       we choose a template.
+
 2015-11-11  Jason Merrill  <jason@redhat.com>
 
        * decl.c (duplicate_decls): When combining typedefs, remove the
index 62659ec90dccef77d7034661dec4d42eccfe7dcd..2e3d48bd297f055701a407fb5b8fdaeb2ea9367a 100644 (file)
@@ -2800,14 +2800,6 @@ check_explicit_specialization (tree declarator,
                  error ("%qD is not a template function", dname);
                  fns = error_mark_node;
                }
-             else
-               {
-                 tree fn = OVL_CURRENT (fns);
-                 if (!is_associated_namespace (CP_DECL_CONTEXT (decl),
-                                               CP_DECL_CONTEXT (fn)))
-                   error ("%qD is not declared in %qD",
-                          decl, current_namespace);
-               }
            }
 
          declarator = lookup_template_function (fns, NULL_TREE);
@@ -2941,6 +2933,14 @@ check_explicit_specialization (tree declarator,
        return error_mark_node;
       else
        {
+         if (!ctype && !was_template_id
+             && (specialization || member_specialization
+                 || explicit_instantiation)
+             && !is_associated_namespace (CP_DECL_CONTEXT (decl),
+                                          CP_DECL_CONTEXT (tmpl)))
+           error ("%qD is not declared in %qD",
+                  tmpl, current_namespace);
+
          tree gen_tmpl = most_general_template (tmpl);
 
          if (explicit_instantiation)
diff --git a/gcc/testsuite/g++.dg/template/explicit-instantiation4.C b/gcc/testsuite/g++.dg/template/explicit-instantiation4.C
new file mode 100644 (file)
index 0000000..72417b4
--- /dev/null
@@ -0,0 +1,7 @@
+void f();
+
+namespace A {
+  template <class T> void f(T) { }
+  using ::f;
+  template void f(int);
+}