consider following code:
struct { int propose(); }; struct a1 : { int propose(int); using a::propose; }; struct b1 : a1 { protected: using a1::propose; public: using a::propose; }; int main() { b1().propose(); } let's compile this: g++ -std=c++11 main.cpp.
i'm getting following compiler error using gnu 4.8.1:
main.cpp: in function 'int main()': main.cpp:2:9: error: 'int a::propose()' inaccessible int propose(); ^ main.cpp:18:18: error: within context b1().propose(); however, code compiles in appleclang 6.0.0.6000056.
i understand there no need using in b1, (in code necessary, had 1 using mistake). in case, why clang compiles it? expected?
in [namespace.udecl], have:
when using-declaration brings names base class derived class scope, member functions , member function templates in derived class override and/or hide member functions , member function templates same name, parameter-type-list (8.3.5), cv-qualification, , ref-qualifier (if any) in base class (rather conflicting).
the standard explicitly says names brought in not conflict names in base class. doesn't bringing in conflicting names.
the section says:
a using-declaration declaration , can therefore used repeatedly (and where) multiple declarations allowed. [ example:
struct b { int i; }; struct x : b { using b::i; using b::i; // error: double member declaration };—end example ]
and interestingly, in following example it's gcc happily compiles (and prints a) while clang allows construction of c rejects call foo ambiguous:
struct { void foo() { std::cout << "a\n"; } }; struct b { void foo() { std::cout << "b\n"; } }; struct c : a, b { using a::foo; using b::foo; }; int main() { c{}.foo(); return 0; } so short answer - suspect underspecified in standard , both compilers doing acceptable things. avoid writing sort of code general sanity.
Comments
Post a Comment