public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/46687] New: Class member lookup ambiguity w/ overloaded static members and using declarations
@ 2010-11-27 21:26 hstong at ca dot ibm.com
  2010-11-28  7:43 ` [Bug c++/46687] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: hstong at ca dot ibm.com @ 2010-11-27 21:26 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Class member lookup ambiguity w/ overloaded static
                    members and using declarations
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: hstong@ca.ibm.com


In the test case below, there is a set of overloaded static member functions
foo() whose true declarations all come from struct A.

While lookup from C would find foo in both B1 and B2, B1::foo refers to the
same
set of entities as B2::foo. There should be no ambiguity; GCC reports
otherwise.

The overload candidates for foo should be unambiguously found on the call and
overload resolution should determine that foo(void) is being called.

I also find it odd that the candidates are listed three times.


### Self-contained source (dataa.cpp):
struct A {
   static int foo();
   static int foo(char);
};

struct B1 : A { using A::foo; };
struct B2 : A { using A::foo; };

struct C : B1, B2 { };

enum { X = sizeof C::foo() };


### Command to reproduce:
g++ -c dataa.cpp


### Compiler output:
dataa.cpp:11:19: error: reference to 'foo' is ambiguous
dataa.cpp:3:15: error: candidates are: static int A::foo(char)
dataa.cpp:2:15: error:                 static int A::foo()
dataa.cpp:2:15: error:                 static int A::foo()
dataa.cpp:3:15: error:                 static int A::foo(char)
dataa.cpp:2:15: error:                 static int A::foo()
dataa.cpp:3:15: error:                 static int A::foo(char)


### g++ -v output:
Using built-in specs.
Target: powerpc64-unknown-linux-gnu
Configured with: ../gcc-4.5.0/configure --prefix=/data/gcc
--program-suffix=-4.5.0 --disable-libssp --disable-libgcj
--enable-version-specific-runtime-libs --with-cpu=default32 --enable-secureplt
--with-long-double-128 --enable-shared --enable-__cxa_atexit
--enable-threads=posix --enable-languages=c,c++,fortran
Thread model: posix
GNU C++ (GCC) version 4.5.0 (powerpc64-unknown-linux-gnu)


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

* [Bug c++/46687] Class member lookup ambiguity w/ overloaded static members and using declarations
  2010-11-27 21:26 [Bug c++/46687] New: Class member lookup ambiguity w/ overloaded static members and using declarations hstong at ca dot ibm.com
@ 2010-11-28  7:43 ` redi at gcc dot gnu.org
  2010-11-28  8:59 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2010-11-28  7:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-28 01:43:26 UTC ---
why do you think it's not ambiguous?

C has two bases of type A, so two copies of A::foo()


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

* [Bug c++/46687] Class member lookup ambiguity w/ overloaded static members and using declarations
  2010-11-27 21:26 [Bug c++/46687] New: Class member lookup ambiguity w/ overloaded static members and using declarations hstong at ca dot ibm.com
  2010-11-28  7:43 ` [Bug c++/46687] " redi at gcc dot gnu.org
@ 2010-11-28  8:59 ` redi at gcc dot gnu.org
  2010-11-28  9:35 ` hstong at ca dot ibm.com
  2012-09-02 11:52 ` fabien at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2010-11-28  8:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-28 01:57:06 UTC ---
C has two copies of the name A::foo, as B1::foo and B2::foo.

if C only saw A::foo then it would be unambiguous because the same members
would be found, as in this variant:

struct A {
   static int foo();
   static int foo(char);
};

struct B1 : A { };
struct B2 : A { };

struct C : B1, B2 { };

enum { X = sizeof C::foo() };


However, because you have using declarations in B1 and B2 name lookup finds
B1::foo and B2::foo ... at least by my reading, which could be wrong


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

* [Bug c++/46687] Class member lookup ambiguity w/ overloaded static members and using declarations
  2010-11-27 21:26 [Bug c++/46687] New: Class member lookup ambiguity w/ overloaded static members and using declarations hstong at ca dot ibm.com
  2010-11-28  7:43 ` [Bug c++/46687] " redi at gcc dot gnu.org
  2010-11-28  8:59 ` redi at gcc dot gnu.org
@ 2010-11-28  9:35 ` hstong at ca dot ibm.com
  2012-09-02 11:52 ` fabien at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: hstong at ca dot ibm.com @ 2010-11-28  9:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Hubert Tong <hstong at ca dot ibm.com> 2010-11-28 04:23:55 UTC ---
(In reply to comment #2)
> However, because you have using declarations in B1 and B2 name lookup finds
> B1::foo and B2::foo ... at least by my reading, which could be wrong

It does find B1::foo and B2::foo, but then again, B1::foo and B2::foo refer to
the same functions. In the N3126 wording, the declaration sets for looking up
B1::foo and B2::foo are the same. I believe the case presented is valid under
both the C++03 and the N3126 wording.

>>>
C++03 subclause 10.2 [class.member.lookup] paragraph 2:
First, every declaration for the name in the class and in each of its base
class sub-objects is considered.
...
Each of these declarations that was introduced by a using-declaration is
considered to be from each sub-object of C that is of the type containing the
declaration designated by the using-declaration. If the resulting set of
declarations are not all from sub-objects of the same type, or the set has a
nonstatic member and includes members from distinct sub-objects, there is an
ambiguity and the program is ill-formed. Otherwise that set is the result of
the lookup.
<<<

My understanding is that the resulting set of declarations are all from
subobjects of the same type (the two subobjects, C::B1::A and C::B2::A) and the
set has no nonstatic members (all functions foo() are static member functions).
>From this paragraph, we have a set of declarations as the result of lookup:
{ ::A::foo(void), ::A::foo(char) }

Overload resolution then takes place.


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

* [Bug c++/46687] Class member lookup ambiguity w/ overloaded static members and using declarations
  2010-11-27 21:26 [Bug c++/46687] New: Class member lookup ambiguity w/ overloaded static members and using declarations hstong at ca dot ibm.com
                   ` (2 preceding siblings ...)
  2010-11-28  9:35 ` hstong at ca dot ibm.com
@ 2012-09-02 11:52 ` fabien at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: fabien at gcc dot gnu.org @ 2012-09-02 11:52 UTC (permalink / raw)
  To: gcc-bugs

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

fabien at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2012-09-02
     Ever Confirmed|0                           |1


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

end of thread, other threads:[~2012-09-02 11:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-27 21:26 [Bug c++/46687] New: Class member lookup ambiguity w/ overloaded static members and using declarations hstong at ca dot ibm.com
2010-11-28  7:43 ` [Bug c++/46687] " redi at gcc dot gnu.org
2010-11-28  8:59 ` redi at gcc dot gnu.org
2010-11-28  9:35 ` hstong at ca dot ibm.com
2012-09-02 11:52 ` fabien at gcc dot gnu.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).