This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/9230: Friend definitions in template classes


>Number:         9230
>Category:       c++
>Synopsis:       Friend definitions in template classes
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jan 08 08:46:07 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     Wolfgang Bangerth
>Release:        unknown-1.0
>Organization:
>Environment:
all versions of gcc
>Description:
I'm not sure about this one:
--------------------------
template <class T> class X {
    friend void f () {};
};

void g() { f(); }
--------------------------
This yields:
h.cc: In function `void g()':
h.cc:5: error: `f' undeclared (first use this function)
h.cc:5: error: (Each undeclared identifier is reported only once for each
   function it appears in.)

On the other hand, this compiles cleanly:
--------------------------
template <class T> class X {
    friend void f () {};
};

template class X<int>;
void g() { f(); }
--------------------------

In other words, the function f() is injected into the global
namespace only upon the first instantiation of the template
class X. Is this the way it is supposed to be?

W.
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]