Following this question about multiple (virtual) inheritance , I would like to learn about a simple MWE that does g ++ 5.2.0 upset, while clang ++ 3.6.2 handles it just fine, without any complaints even when setting -Wall and -Wextra . So here is the MWE:
class Z {}; class A : virtual Z { protected: A() {} }; class B : virtual Z { protected: B() {} }; class C : A, B { public: C() : A{}, B{} {} }; int main() { C c{}; return 0; }
Unlike clang ++, g ++ complains as follows:
gccodd.c++: In constructor 'C::C()': gccodd.c++:2:34: error: 'A::A()' is protected class A : virtual Z { protected: A() {} }; ^ gccodd.c++:4:39: error: within this context class C : A, B { public: C() : A{}, B{} {} }; ^ gccodd.c++:3:34: error: 'B::B()' is protected class B : virtual Z { protected: B() {} }; ^ gccodd.c++:4:39: error: within this context class C : A, B { public: C() : A{}, B{} {} }; ^
Replacing uniform initialization in the C constructor with the old form works fine, although both clang ++ and g ++ are happy with the following:
class C : A, B { public: C() : A(), B() {} };
This provides two obvious options:
- The code somehow violates the standard, making the result undefined (i.e. any result will be acceptable).
- One of the two compilers has an error related to uniform initialization and multiple + virtual inheritance.
If it is a vote question, (1) can win because icpc 15.0.0 says the following:
gccodd.c++(4): error #453: protected function "A::A()" (declared at line 2) is not accessible through a "A" pointer or object class C : public virtual A, public virtual B { public: C() : A{}, B{} {} }; ^ gccodd.c++(4): error #453: protected function "B::B()" (declared at line 3) is not accessible through a "B" pointer or object class C : public virtual A, public virtual B { public: C() : A{}, B{} {} }; ^
So is it (1) or (2)? And if this is the first case, then what happened to my MWE?