This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: friend declaration implicitly provides a prototype
- From: Bernardo Innocenti <bernie at develer dot com>
- To: Giovanni Bajo <giovannibajo at libero dot it>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 18 Dec 2003 00:16:14 +0100
- Subject: Re: friend declaration implicitly provides a prototype
- Organization: Develer S.r.l.
- References: <3FDF71C7.5070207@develer.com> <0a2301c3c491$8400e8e0$55bb2997@bagio>
Giovanni Bajo wrote:
Bernardo Innocenti <bernie@develer.com> wrote:
class Foo
{
// No prototype for bar() given
friend void bar(int);
};
void some_function()
{
bar(10); // No error for undeclared function!
}
What the standard explicitly requires is that bar()
can be accessed in Foo as if it was declared.
This doesn't mean bar(int) is implicitly declared
everywhere, right?
The friend declaration introduces a predeclaration in the enclosing namespace,
but the function should not be found under unqualified lookup until it's
declared (see §7.3.1.2/3). I think this is a known problem in GCC, but would
you please file a bugreport anyway, so that we're sure it doesn't get lost?
These open bugs seem to describe similar problems:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=1016
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8280
My test case appears most appropriate for PR8280, although both bugs
might originate from the same fundamental problem of letting friend
declarations appear in the global namespace instead of limiting them
to class scope as required by 7.3.1.2/3.
This problem seems easy to analyze. I'd like to give it a try as an
opportunity to teach myself something about the C++ frontend.
Will you be helping me in case I get stuck? ;-)
--
// Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/ http://www.develer.com/