public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/36163]  New: Friend declaration confused by namespace/using
@ 2008-05-06 21:30 igodard at pacbell dot net
  2008-05-06 21:32 ` [Bug c++/36163] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: igodard at pacbell dot net @ 2008-05-06 21:30 UTC (permalink / raw)
  To: gcc-bugs

This code:

namespace   name {
    class foo {
    public:
        template<class T>
        void    baz(T& t) { int i = t.dat; }
        };
    }
using namespace name;
class bar {
friend class  foo;
    int dat;
    };
int main() {
    bar b;
    foo f;
    f.baz(b);
    }

gets you:
~/ootbc/members$ g++ foo.cc
foo.cc: In member function 'void name::foo::baz(T&) [with T = bar]':
foo.cc:16:   instantiated from here
foo.cc:11: error: 'int bar::dat' is private
foo.cc:5: error: within this context


-- 
           Summary: Friend declaration confused by namespace/using
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: igodard at pacbell dot net


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


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

* [Bug c++/36163] Friend declaration confused by namespace/using
  2008-05-06 21:30 [Bug c++/36163] New: Friend declaration confused by namespace/using igodard at pacbell dot net
@ 2008-05-06 21:32 ` pinskia at gcc dot gnu dot org
  2008-05-06 21:40 ` igodard at pacbell dot net
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-05-06 21:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2008-05-06 21:31 -------
I don't think this is a bug, the friend class here is really ::foo.


-- 


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


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

* [Bug c++/36163] Friend declaration confused by namespace/using
  2008-05-06 21:30 [Bug c++/36163] New: Friend declaration confused by namespace/using igodard at pacbell dot net
  2008-05-06 21:32 ` [Bug c++/36163] " pinskia at gcc dot gnu dot org
@ 2008-05-06 21:40 ` igodard at pacbell dot net
  2009-10-30  2:48 ` mdjones0978-gccbugs at yahoo dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: igodard at pacbell dot net @ 2008-05-06 21:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from igodard at pacbell dot net  2008-05-06 21:39 -------
Isn't ::foo the using'd class from name? If not, how does one befriend a class
that comes from a using?


-- 


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


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

* [Bug c++/36163] Friend declaration confused by namespace/using
  2008-05-06 21:30 [Bug c++/36163] New: Friend declaration confused by namespace/using igodard at pacbell dot net
  2008-05-06 21:32 ` [Bug c++/36163] " pinskia at gcc dot gnu dot org
  2008-05-06 21:40 ` igodard at pacbell dot net
@ 2009-10-30  2:48 ` mdjones0978-gccbugs at yahoo dot com
  2009-10-30 12:14 ` redi at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mdjones0978-gccbugs at yahoo dot com @ 2009-10-30  2:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from mdjones0978-gccbugs at yahoo dot com  2009-10-30 02:48 -------
I think it is a bug, because the class test is declared at the scope :: (before
the namespace), then used below.  The solution is to explicitly state the fact
it is from ::

#include <assert.h>

class Test;

namespace Boo {
  class Outer {
    friend class Test;  // replace with ::Test to fix
  private:
    int _o;
    class Inner {
      friend class Test; // replace with ::Test to fix
      int _i;
    };
  };
}

class Test {
public:
  void DoTest() {
    Boo::Outer::Inner  oi;
    assert(oi._i == 3);
  }
};

main(int argc, char *argv[]) {

  Test x;
  x.DoTest();

}


-- 


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


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

* [Bug c++/36163] Friend declaration confused by namespace/using
  2008-05-06 21:30 [Bug c++/36163] New: Friend declaration confused by namespace/using igodard at pacbell dot net
                   ` (2 preceding siblings ...)
  2009-10-30  2:48 ` mdjones0978-gccbugs at yahoo dot com
@ 2009-10-30 12:14 ` redi at gcc dot gnu dot org
  2009-10-30 12:16 ` redi at gcc dot gnu dot org
  2009-10-30 12:24 ` paolo dot carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu dot org @ 2009-10-30 12:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from redi at gcc dot gnu dot org  2009-10-30 12:14 -------
(In reply to comment #2)
> Isn't ::foo the using'd class from name?

No, see 7.3.1.2 [namespace.memdef]/3 - an unqualified friend declaration refers
to a member of the innermost enclosing namespace. Names brought into a
namespace scope by a using directive are not members of a namespace.

> If not, how does one befriend a class
> that comes from a using?

You don't, you need to qualify it with the namespace


-- 


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


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

* [Bug c++/36163] Friend declaration confused by namespace/using
  2008-05-06 21:30 [Bug c++/36163] New: Friend declaration confused by namespace/using igodard at pacbell dot net
                   ` (3 preceding siblings ...)
  2009-10-30 12:14 ` redi at gcc dot gnu dot org
@ 2009-10-30 12:16 ` redi at gcc dot gnu dot org
  2009-10-30 12:24 ` paolo dot carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu dot org @ 2009-10-30 12:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from redi at gcc dot gnu dot org  2009-10-30 12:15 -------
(In reply to comment #3)
> I think it is a bug, because the class test is declared at the scope ::

A friend declaration specifies a class that belongs to the innermost enclosing
namespace scope, outer scopes are not considered.

This is not a bug.


-- 


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


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

* [Bug c++/36163] Friend declaration confused by namespace/using
  2008-05-06 21:30 [Bug c++/36163] New: Friend declaration confused by namespace/using igodard at pacbell dot net
                   ` (4 preceding siblings ...)
  2009-10-30 12:16 ` redi at gcc dot gnu dot org
@ 2009-10-30 12:24 ` paolo dot carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-10-30 12:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from paolo dot carlini at oracle dot com  2009-10-30 12:24 -------
Ok, let's close it as invalid. For the record, Comeau 4.3.10.1 Beta2 also
rejects it.


-- 

paolo dot carlini at oracle dot com changed:

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


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


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

end of thread, other threads:[~2009-10-30 12:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-06 21:30 [Bug c++/36163] New: Friend declaration confused by namespace/using igodard at pacbell dot net
2008-05-06 21:32 ` [Bug c++/36163] " pinskia at gcc dot gnu dot org
2008-05-06 21:40 ` igodard at pacbell dot net
2009-10-30  2:48 ` mdjones0978-gccbugs at yahoo dot com
2009-10-30 12:14 ` redi at gcc dot gnu dot org
2009-10-30 12:16 ` redi at gcc dot gnu dot org
2009-10-30 12:24 ` paolo dot carlini at oracle dot com

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).