This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/9230: Friend definitions in template classes
- From: bangerth at ticam dot utexas dot edu
- To: gcc-gnats at gcc dot gnu dot org
- Date: 8 Jan 2003 16:40:07 -0000
- Subject: c++/9230: Friend definitions in template classes
- Reply-to: bangerth at ticam dot utexas dot edu
>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: