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: C++ language lawyer question


Nathan Sidwell <nathan@codesourcery.com> writes:

| Albert Chin wrote:
| > In the process of compiling KDE 3.2 on IRIX 6.5 and Tru64 UNIX 5.1
| > with the respective vendor C++ compilers, I ran into a namespace
| > issue. Consider the following:
| > $ cat a.h
| > class KMAcctImap;
| > namespace KIO {
| >   class Job {
| >   public:
| >     int b;
| >   };
| > }
| > namespace KMail {
| >   class ImapJob {
| >     friend class KMAcctImap;
| AFAICT [11.4]/9 indicates that this already means ::KMAcctImap,

I disagree.  11.4/9 says:

  If a friend declaration appears in a local class (9.8) and the name
  specified is an unqualified name, a prior declaration is looked up
  without considering scopes that are outside the innermost enclosing
  non-class scope. For a friend function declaration, if there is no
  prior declaration, the program is ill-formed. For a friend class
  declaration, if there is no prior declaration, the class that is
  specified belongs to the innermost enclosing non-class scope, but if
  it is subsequently referenced, its name is not found by name lookup
  until a matching declaration is provided in the innermost enclosing
  nonclass scope. 

Here, the friend declaration *does not appear in local class*.
And even if it were local class, the innermost nonclass scope is that
of the namespace KMail, not the global scope.

The relevant chapter and verse for the particular case under
discussion is explicitly covered by 7.3.1.2/3:

  Every name first declared in a namespace is a member of that
  namespace. If a friend declaration in a non-local class first
  declares a class or function83) the friend class or function is a
  member of the innermost enclosing namespace. The name of the friend
  is not found by simple name lookup until a matching declaration
  is provided in that namespace scope (either before or after the
  class declaration granting friendship). If a friend function is
  called, its name may be found by the name lookup that considers
  functions from namespaces and classes associated with the types of
  the function arguments (3.4.2). When looking for a prior declaration
  of a class or a function declared as a friend, and when the name of
  the friend class or function is neither a qualified name nor a
  template-id, scopes outside the innermost enclosing namespace
  scope are not considered.

Again, the innermost namespace to consider is KMail, not the global
namespace. Hence, GCC behaviour is wrong.

-- Gaby


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