MSVC, Clang and GCC disagree on this code:
struct Base { int x; };
struct Der1 : public Base {};
struct Der2 : public Base {};
struct AllDer : public Der1, public Der2 {
void foo() {
Der1::Base::x = 5;
}
};
GCC:
<source>: In member function 'void AllDer::foo()':
<source>:10:21: error: 'Base' is an ambiguous base of 'AllDer'
10 | Der1::Base::x = 5;
| ^
Compiler returned: 1
Clang gives a similar error, and MSVC gives no error.
Who is right here?
I suppose this is covered in [class.member.lookup], but I have difficulties understanding what it is trying to tell me for this case. Please quote the relevant parts and if possible explain in plain English.
PS: Inspired by this question Why is Reference to Base Class ambiguous with :: -operator trough derived class?
PPS: Actually my doubt is whether Der1::Base
refers to the type, that would be Base
(and then Der2::Base
is exactly the same type), or to the subobject. I am convinced that it is the first, but if it is the latter then MSVC would be right.