public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/41960]  New: g++: friend introduce name into class, violate standard
@ 2009-11-06  3:51 pi3orama at gmail dot com
  2009-11-06  3:52 ` [Bug c++/41960] " pi3orama at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: pi3orama at gmail dot com @ 2009-11-06  3:51 UTC (permalink / raw)
  To: gcc-bugs

below code cannot be compiled:

-----------
#define TYPE    N::C
#define ASSIGN  do {} while(0)
//#define ASSIGN        do { x->i = 0;} while(0)
//#define TYPE  N::B
namespace N {
        class B;
        class C;
}
void func(TYPE * x);
namespace N {
        class B { int i; };
        class C {
                int i;
                friend void func(TYPE * x);
        };
}
void func(TYPE * x) { ASSIGN; }
int main()
{
        TYPE x;
        func(&x);
        return 0;
}
-----------

g++ report:

------------
/test-cpp.cpp: In function 'int main()':
./test-cpp.cpp:22: error: call of overloaded 'func(N::C*)' is ambiguous
./test-cpp.cpp:18: note: candidates are: void func(N::C*)
./test-cpp.cpp:15: note:                 void N::func(N::C*)
------------

change

#define TYPE  N::C

to 

#define TYPE    N::B

then the code can be compiled.

According to [namespace.memdef] and [basic.scope.pdecl]:

---------------
friend declarations refer to functions or classes that are members of the
nearest enclosing namespace, but they do not introduce new names into that
namespace (7.3.1.2).
---------------

According to standard, ::func(N::C * x) shouldn't become friend of N::C, but
there should no ambiguous, because 'friend void func(TYPE * x);' look for
N::func(N::C *), and it doesn't exist at all. According to [namespace.memdef],
the names introduced by 'friend' is invisible until its real declaration.

It seems that, g++ wrongly introduces a name: N::func(N::C*) into namespace N,
and when calling func(N::C*), it follows koenig lookup and finds
N::func(N::C*). In the situation of 'friend void N::func(N::B*)', g++ works
correctly.


-- 
           Summary: g++: friend introduce name into class, violate standard
           Product: gcc
           Version: 4.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pi3orama at gmail dot com


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


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

* [Bug c++/41960] g++: friend introduce name into class, violate standard
  2009-11-06  3:51 [Bug c++/41960] New: g++: friend introduce name into class, violate standard pi3orama at gmail dot com
@ 2009-11-06  3:52 ` pi3orama at gmail dot com
  2009-11-06  3:59 ` [Bug c++/41960] g++: friend introduce name into namespace, " pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pi3orama at gmail dot com @ 2009-11-06  3:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pi3orama at gmail dot com  2009-11-06 03:52 -------
following is my g++ -v:

Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.3.4/work/gcc-4.3.4/configure
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.3.4
--includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.3.4
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.3.4/man
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.3.4/info
--with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4
--host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec
--disable-fixed-point --enable-nls --without-included-gettext
--with-system-zlib --disable-checking --disable-werror --enable-secureplt
--disable-multilib --enable-libmudflap --disable-libssp --enable-libgomp
--disable-libgcj --with-arch=i686 --enable-languages=c,c++,treelang,fortran
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --with-bugurl=http://bugs.gentoo.org/
--with-pkgversion='Gentoo 4.3.4 p1.0, pie-10.1.5'
Thread model: posix
gcc version 4.3.4 (Gentoo 4.3.4 p1.0, pie-10.1.5) 


-- 


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


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

* [Bug c++/41960] g++: friend introduce name into namespace, violate standard
  2009-11-06  3:51 [Bug c++/41960] New: g++: friend introduce name into class, violate standard pi3orama at gmail dot com
  2009-11-06  3:52 ` [Bug c++/41960] " pi3orama at gmail dot com
@ 2009-11-06  3:59 ` pinskia at gcc dot gnu dot org
  2009-11-06  4:09 ` pi3orama at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-11-06  3:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2009-11-06 03:59 -------
This is correct argument dependent lookup is supposed to find N::func for N::C.
 You just cannot call N::func directly.


-- 

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=41960


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

* [Bug c++/41960] g++: friend introduce name into namespace, violate standard
  2009-11-06  3:51 [Bug c++/41960] New: g++: friend introduce name into class, violate standard pi3orama at gmail dot com
  2009-11-06  3:52 ` [Bug c++/41960] " pi3orama at gmail dot com
  2009-11-06  3:59 ` [Bug c++/41960] g++: friend introduce name into namespace, " pinskia at gcc dot gnu dot org
@ 2009-11-06  4:09 ` pi3orama at gmail dot com
  2009-11-06  4:20 ` pinskia at gcc dot gnu dot org
  2009-11-06  4:40 ` pi3orama at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pi3orama at gmail dot com @ 2009-11-06  4:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pi3orama at gmail dot com  2009-11-06 04:09 -------
Then why

#define TYPE  N::B

works?

why argument dependent lookup doesn't take effect? Both B and func are in
namespace N.


-- 


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


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

* [Bug c++/41960] g++: friend introduce name into namespace, violate standard
  2009-11-06  3:51 [Bug c++/41960] New: g++: friend introduce name into class, violate standard pi3orama at gmail dot com
                   ` (2 preceding siblings ...)
  2009-11-06  4:09 ` pi3orama at gmail dot com
@ 2009-11-06  4:20 ` pinskia at gcc dot gnu dot org
  2009-11-06  4:40 ` pi3orama at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-11-06  4:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2009-11-06 04:19 -------
(In reply to comment #3)
> Then why
> 
> #define TYPE  N::B
> 
> works?
> 
> why argument dependent lookup doesn't take effect? Both B and func are in
> namespace N.

Because N::func is only a friend of N::C so it is only found for N::C.


-- 


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


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

* [Bug c++/41960] g++: friend introduce name into namespace, violate standard
  2009-11-06  3:51 [Bug c++/41960] New: g++: friend introduce name into class, violate standard pi3orama at gmail dot com
                   ` (3 preceding siblings ...)
  2009-11-06  4:20 ` pinskia at gcc dot gnu dot org
@ 2009-11-06  4:40 ` pi3orama at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pi3orama at gmail dot com @ 2009-11-06  4:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pi3orama at gmail dot com  2009-11-06 04:40 -------
I find a clause in the standard:

[basic.lookup.argdep]:

Any namespace-scope friend functions or friend function templates declared in
associated classes are visible within their respective namespaces even if they
are not visible during an ordinary lookup.

g++ is right.


-- 


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


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

end of thread, other threads:[~2009-11-06  4:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-06  3:51 [Bug c++/41960] New: g++: friend introduce name into class, violate standard pi3orama at gmail dot com
2009-11-06  3:52 ` [Bug c++/41960] " pi3orama at gmail dot com
2009-11-06  3:59 ` [Bug c++/41960] g++: friend introduce name into namespace, " pinskia at gcc dot gnu dot org
2009-11-06  4:09 ` pi3orama at gmail dot com
2009-11-06  4:20 ` pinskia at gcc dot gnu dot org
2009-11-06  4:40 ` pi3orama at gmail 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).