c++/9230: Friend definitions in template classes

Gabriel Dos Reis gdr@integrable-solutions.net
Wed Jan 8 19:06:00 GMT 2003


The following reply was made to PR c++/9230; it has been noted by GNATS.

From: Gabriel Dos Reis <gdr@integrable-solutions.net>
To: bangerth@ticam.utexas.edu
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/9230: Friend definitions in template classes
Date: 08 Jan 2003 20:01:57 +0100

 bangerth@ticam.utexas.edu writes:
 
 | 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(); }
 
 This  is a bogus behaviour of g++ I came across from time to time.
 More generally, we have BIG problems in the current name-lookup
 implementation.
 
 | 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?
 
 No.
 
 There is no declaration of f() in the global scope.
 
 -- Gaby



More information about the Gcc-prs mailing list