From: Giovanni Bajo Date: Thu, 26 Jun 2003 12:59:46 +0000 (+0200) Subject: re PR c++/8266 (Explicit instantiation of a template outside its namespace is broken) X-Git-Tag: releases/gcc-3.4.0~5457 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2f54a1db5eac0c0ba696e8acaf124c659a41adfb;p=thirdparty%2Fgcc.git re PR c++/8266 (Explicit instantiation of a template outside its namespace is broken) From Giovanni Bajo 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1ad3dc1954f1..4a36f176d987 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2003-06-26 Giovanni Bajo + + 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 PR c++/10990 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index e29d434c0009..282c788180fb 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 08f39ab4f47a..68dbc9f6c6c3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2003-06-26 Giovanni Bajo + + PR c++/8266 + * g++.dg/template/explicit-instantiation3.C: New test. + 2003-06-26 Eric Botcazou * 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 index 000000000000..fac092e6cbff --- /dev/null +++ b/gcc/testsuite/g++.dg/template/explicit-instantiation3.C @@ -0,0 +1,31 @@ +// { dg-do compile } +// Origin: +// c++/8266: Explicit instantiation of a template outside its namespace is +// broken + +namespace N +{ + template T foo (T) + { return T (); } + + struct A + { + template + struct B {}; + }; + + template + struct C {}; + + template double foo(double); + template float foo(float); + template struct A::B<0>; + template struct C<0>; +} + +template int N::foo(int); +template char N::foo(char); +template struct N::A::B<1>; +template struct N::C<1>; + +