G++ does not seem to search for classes for friend class declaration outside
the current namespace.

The following code does not work with G++ 4.0.3/4.1.0.
----
class bar;

namespace NS
{
  class foo
  {
    private:
      friend class bar;
      static int var;
  };

  int foo::var = 0;
}


class bar
{
  public:
    bar()
    {
      NS::foo::var = 1;
    }
};

int main()
{
   bar i;
}
-------

Result is:
nstest.cc: In constructor 'bar::bar()':
nstest.cc:12: error: 'int NS::foo::var' is private
nstest.cc:21: error: within this context

The above code works with g++ 3.4.4.
A work around for 4.x is defining friend class as "::bar".


gcc -v:
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,fortran,objc,obj-c++,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.1-1.4.2.0/jre --enable-mpfr
--with-tune=i686 --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.0 (Debian 4.1.0-1)

System:
Linux maestro 2.6.16 #1 SMP PREEMPT Mon Mar 20 21:20:19 EET 2006 i686 GNU/Linux


-- 
           Summary: friend class declaration doesn't search out of the
                    namespace
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pvuorela at iki dot fi


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

Reply via email to