This is the mail archive of the gcc@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]

Re: friend declaration implicitly provides a prototype


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/



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