Gcc's friend-mechanism seems to expand to nested classes as well, although
the C++ standard explicitly tells differently.

The following example is almost straight from the C++ standard (11.4/2). The
only change is that inheritance is commented out for class X (in order to
remove the first error in the example). Gcc compiles this with no error
messages, even with -Wall -pedantic

// test.cc
class A {
  class B { };
  friend class X;
};

// INHERITANCE BELOW COMMENTED OUT BY ME
class X /* : A::B */ { // ill-formed: A::B cannot be accessed
  // in the base-clause for X
  A::B mx; // OK: A::B used to declare member of X
  class Y : A::B { // OK: A::B used to declare member of X
// !!!!!!!!!!! The illegal line below compiles fine !!!!!!!!!!
    A::B my; // ill-formed: A::B cannot be accessed
    // to declare members of nested class of X
  };
};

Environment:
System: Linux mustikkakukko 2.6.18.8-0.3-default #1 SMP Tue Apr 17 08:42:35 UTC
2007 x86_64 x86_64 x86_64 GNU/Linux
Architecture: x86_64


host: x86_64-suse-linux-gnu
build: x86_64-suse-linux-gnu
target: x86_64-suse-linux-gnu
configured with: ../gcc-4.2.1/configure --prefix=/usr/local/gcc-4.2.1
--bindir=/usr/local/gcc-4.2.1/bin64 --enable-languages=c,c++
--enable-__cxa_atexit --host=x86_64-suse-linux --with-arch=nocona
--with-tune=nocona

How-To-Repeat:
  g++ -W -Wall -pedantic -c test.cc
  (No errors result in compilation.)


-- 
           Summary: C++: Invalid interpretation of friendness with nested
                    classes
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bitti at iki dot fi
 GCC build triplet: x86_64-suse-linux-gnu
  GCC host triplet: x86_64-suse-linux-gnu
GCC target triplet: x86_64-suse-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33468

Reply via email to