diff options
author | Giovanni Bajo <giovannibajo@libero.it> | 2003-06-26 14:59:46 +0200 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2003-06-26 12:59:46 +0000 |
commit | 2f54a1db5eac0c0ba696e8acaf124c659a41adfb (patch) | |
tree | 162ef2b655a1102fc1a381f676a3629cb63ecd89 | |
parent | f5416098688606d9eaef9728de245275fd27d8db (diff) | |
download | gcc-2f54a1db5eac0c0ba696e8acaf124c659a41adfb.zip gcc-2f54a1db5eac0c0ba696e8acaf124c659a41adfb.tar.gz gcc-2f54a1db5eac0c0ba696e8acaf124c659a41adfb.tar.bz2 |
re PR c++/8266 (Explicit instantiation of a template outside its namespace is broken)
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
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/pt.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/explicit-instantiation3.C | 31 |
4 files changed, 56 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1ad3dc1..4a36f17 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index e29d434..282c788 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 08f39ab..68dbc9f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..fac092e --- /dev/null +++ b/gcc/testsuite/g++.dg/template/explicit-instantiation3.C @@ -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>; + + |