public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/27123]  New: friend class declaration doesn't search out of the namespace
@ 2006-04-11 18:52 pvuorela at iki dot fi
  2006-04-11 18:56 ` [Bug c++/27123] " pinskia at gcc dot gnu dot org
  2007-05-09 22:10 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: pvuorela at iki dot fi @ 2006-04-11 18:52 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/27123] friend class declaration doesn't search out of the namespace
  2006-04-11 18:52 [Bug c++/27123] New: friend class declaration doesn't search out of the namespace pvuorela at iki dot fi
@ 2006-04-11 18:56 ` pinskia at gcc dot gnu dot org
  2007-05-09 22:10 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-04-11 18:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-04-11 18:56 -------
You did not read the changes page:
http://gcc.gnu.org/gcc-4.0/changes.html

When declaring a friend class using an unqualified name, classes outside the
innermost non-class scope are not searched: 
class A;
namespace N {
  class B {
    friend class A;   // Refer to N::A which has not been declared yet
                      // because name outside namespace N are not searched
    friend class ::A; // Refer to ::A
  };
}
Hiding the friend name until declaration is still not implemented. 



This is how C++ is defined.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/27123] friend class declaration doesn't search out of the namespace
  2006-04-11 18:52 [Bug c++/27123] New: friend class declaration doesn't search out of the namespace pvuorela at iki dot fi
  2006-04-11 18:56 ` [Bug c++/27123] " pinskia at gcc dot gnu dot org
@ 2007-05-09 22:10 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-05-09 22:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-05-09 23:10 -------
http://gcc.gnu.org/ml/gcc-patches/2004-12/msg00021.html

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

Look at:
http://gcc.gnu.org/ml/gcc/2004-03/msg00668.html
for a real description of why this is invalid code.


-- 


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-05-09 22:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-11 18:52 [Bug c++/27123] New: friend class declaration doesn't search out of the namespace pvuorela at iki dot fi
2006-04-11 18:56 ` [Bug c++/27123] " pinskia at gcc dot gnu dot org
2007-05-09 22:10 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).