]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/8266 (Explicit instantiation of a template outside its namespace is broken)
authorGiovanni Bajo <giovannibajo@libero.it>
Thu, 26 Jun 2003 12:59:46 +0000 (14:59 +0200)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 26 Jun 2003 12:59:46 +0000 (12:59 +0000)
From  Giovanni Bajo  <giovannibajo@libero.it>
cp:
       PR c++/8266
        * pt.c (check_explicit_specialization): When looking up a
        template function from an identifier outside class-scope, bind
        it to CP_DECL_CONTEXT.
testsuite:
        PR c++/8266
        * g++.dg/template/explicit-instantiation3.C: New test.

From-SVN: r68527

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

index 1ad3dc1954f1b7654276f3673a80ddb5ba4aa95e..4a36f176d987865e999a322251438ad6fcb31d98 100644 (file)
@@ -1,3 +1,10 @@
+2003-06-26  Giovanni Bajo  <giovannibajo@libero.it>
+
+        PR c++/8266
+        * pt.c (check_explicit_specialization): When looking up a
+        template function from an identifier outside class-scope, bind
+        it to CP_DECL_CONTEXT.
+
 2003-06-25  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/10990
index e29d434c00097d8c5d999b3dee945b91a67945ce..282c788180fb507a1f107f735c87e5780c052494 100644 (file)
@@ -1629,15 +1629,21 @@ check_explicit_specialization (tree declarator,
        {
          tree fns;
 
-         my_friendly_assert (TREE_CODE (declarator) == IDENTIFIER_NODE, 
-                             0);
-         if (!ctype)
-           fns = IDENTIFIER_NAMESPACE_VALUE (dname);
-         else
+         my_friendly_assert (TREE_CODE (declarator) == IDENTIFIER_NODE, 0);
+         if (ctype)
            fns = dname;
+         else
+           {
+             /* If there is no class context, the explicit instantiation
+                 must be at namespace scope.  */
+             my_friendly_assert (DECL_NAMESPACE_SCOPE_P (decl), 20030625);
+
+             /* Find the namespace binding, using the declaration
+                 context.  */
+             fns = namespace_binding (dname, CP_DECL_CONTEXT (decl));
+           }
 
-         declarator = 
-           lookup_template_function (fns, NULL_TREE);
+         declarator = lookup_template_function (fns, NULL_TREE);
        }
 
       if (declarator == error_mark_node)
index 08f39ab4f47a2d9313608c8774b337feec3fb3c5..68dbc9f6c6c3bb464af72d69e42ca84524b91a21 100644 (file)
@@ -1,3 +1,8 @@
+2003-06-26  Giovanni Bajo  <giovannibajo@libero.it>
+
+        PR c++/8266
+        * g++.dg/template/explicit-instantiation3.C: New test.
+
 2003-06-26  Eric Botcazou <ebotcazou@libertysurf.fr>
 
        * gcc.dg/20030626-1.c: Use signed char.
diff --git a/gcc/testsuite/g++.dg/template/explicit-instantiation3.C b/gcc/testsuite/g++.dg/template/explicit-instantiation3.C
new file mode 100644 (file)
index 0000000..fac092e
--- /dev/null
@@ -0,0 +1,31 @@
+// { dg-do compile }
+// Origin: <sebor at roguewave dot com>
+// c++/8266: Explicit instantiation of a template outside its namespace is
+//  broken
+
+namespace N
+{
+  template <class T> T foo (T)
+  { return T (); }
+
+  struct A
+  {
+    template <int N>
+    struct B {};
+  };
+
+  template <int M>
+  struct C {};
+
+  template double foo(double);
+  template float  foo<float>(float);
+  template struct A::B<0>;
+  template struct C<0>;
+}
+
+template int    N::foo(int);
+template char   N::foo<char>(char);
+template struct N::A::B<1>;
+template struct N::C<1>;
+
+