[C++ PATCH] Fix PR/8266

Giovanni Bajo giovannibajo@libero.it
Wed Jun 25 00:56:00 GMT 2003


Hello,

PR/8266 was about an explicit instantiation of a function template (using a
non template-id form) outside of its namespace of definition. The problem is
that when we were finding the namespace binding, we were ignoring the
declaration context of the function.

This patch has been bootstrapped on i686-pc-cygwin (c, c++, java), and
tested with "make check-g++" with no new regressions. OK for mainline?

Giovanni Bajo


2003-06-24  Giovanni Bajo  <giovannibajo@libero.it>

        PR c++/8266
        * pt.c (check_explicit_specialization): When looking up the
        template function from an identifier within class-scope, bind
        it to CP_DECL_CONTEXT before.

2003-06-24  Giovanni Bajo  <giovannibajo@libero.it>

        PR c++/8266
        * g++.dg/template/explicit-instantiation2.C: New test.


Index: pt.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.697
diff -c -w -p -r1.697 pt.c
*** pt.c        3 Jun 2003 13:01:43 -0000       1.697
--- pt.c        24 Jun 2003 15:01:17 -0000
*************** check_explicit_specialization (declarato
*** 1678,1684 ****
          my_friendly_assert (TREE_CODE (declarator) == IDENTIFIER_NODE,
                              0);
          if (!ctype)
!           fns = IDENTIFIER_NAMESPACE_VALUE (dname);
          else
            fns = dname;

--- 1678,1693 ----
          my_friendly_assert (TREE_CODE (declarator) == IDENTIFIER_NODE,
                              0);
          if (!ctype)
!           {
!             /* If there is no class context, the explicit instantiation
!                must be at namespace scope.  */
!             if (!DECL_NAMESPACE_SCOPE_P (decl))
!               abort();
!
!             /* Find the namespace binding, using the declaration
!                context.  */
!             fns = namespace_binding (dname, CP_DECL_CONTEXT (decl));
!           }
          else
            fns = dname;


// { 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>;



More information about the Gcc-patches mailing list