5

Is the following program well-formed or ill-formed according to the c++ standard?

struct A { protected: static const int x = 0; };
struct B : A {};
struct C : A { using A::x; };
struct D : B, C {};

int main() { D::x; }

Different compilers gives different results. Clang rejects it and GCC accepts it:

I think that the program is well-formed (and therefore that clang has the bug for rejecting it) by http://eel.is/c++draft/class.paths#1, but i'm not sure:

If a name can be reached by several paths through a multiple inheritance graph, the access is that of the path that gives most access.

Supremum
  • 542
  • 7
  • 23
  • This looks like a Clang bug. If we move the using-declaration to `B` instead of `C` [the code compiles](http://coliru.stacked-crooked.com/a/9299fb64ff89f6b7). GCC also seems to be buggy in this area as well, try changing `x` into a function, then the lookup becomes ambiguous. – David G Aug 09 '15 at 01:48
  • That asymmetry in clang makes the case against it stronger. About GCC: I tried using a static function first, and yes GCC gives a bug then, but a different kind of bug (ambiguous name lookup). That GCC bug i'm already quite sure about since inconsistency between static data member and static function. It's strange how the manage to get such inconsistency, did they copy paste code when writing the compiler? – Supremum Aug 09 '15 at 11:13
  • This seems to be the diamond problem. – Vinay Shukla Aug 10 '15 at 13:55

0 Answers0