c++/9230: Friend definitions in template classes

bangerth@ticam.utexas.edu bangerth@ticam.utexas.edu
Mon Jan 13 05:17:00 GMT 2003


>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:



More information about the Gcc-bugs mailing list