Summary: | Class member lookup ambiguity w/ overloaded static members and using declarations | ||
---|---|---|---|
Product: | gcc | Reporter: | Hubert Tong <hstong> |
Component: | c++ | Assignee: | fabien |
Status: | ASSIGNED --- | ||
Severity: | normal | CC: | egallager, fabien, fang, webrown.cpp |
Priority: | P3 | Keywords: | accepts-invalid, rejects-valid, wrong-code |
Version: | 4.5.0 | ||
Target Milestone: | --- | ||
See Also: | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41796 | ||
Host: | powerpc64-unknown-linux-gnu | Target: | powerpc64-unknown-linux-gnu |
Build: | Known to work: | ||
Known to fail: | 3.2, 4.1.2, 4.3.2, 4.4.0, 4.5.0 | Last reconfirmed: | 2012-09-02 00:00:00 |
Description
Hubert Tong
2010-11-27 21:19:15 UTC
why do you think it's not ambiguous? C has two bases of type A, so two copies of A::foo() 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 (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. |