Nested class hidden by multiple inheritance

Is this code valid C ++ (11)?

struct Base { template <typename> struct nested; }; struct Derived1 : Base { }; struct Derived2 : Base { }; struct Derived3 : Derived1, Derived2 { }; typedef Derived3::nested<int> xxx; 

What i know

The above code does not compile with:

  • Apple LLVM 5.0 (clang-500.2.75)
  • Clang 3.4

But it successfully compiles with:

  • gcc 4.9.0 20131110 (experimental)
  • gcc 4.8

Also, if I change the nested type to a type without a template, i.e.

 struct Base { struct nested; }; ... typedef Derived3::nested xxx; 

then it works with the above compilers.

[edit] Changing the structure of a nested template to a template alias also does not change anything;

 template <typename> struct dependent { struct type; }; struct Base { template <typename T> using nested = typename dependent<T>::type; }; 

gives the same results with the above compilers. [end edit]

From N3242 ยง10.1 [class .mi]

A class can be an indirect base class more than once and can be a direct and indirect base class. There are limited things you can do with this class. Non-static data members and member functions of a direct base class cannot be specified in the scope of a derived class. However, static elements, enumerations, and types can be explicitly mentioned.

I think this means the code must be valid, but I'm not sure.

+7
c ++ gcc multiple-inheritance clang nested-class
source share
1 answer

It's good that GCC is correct or more useful (it adheres to the standard VERY strongly)

It is impossible to understand why the definition would be ambiguous because you are talking about a type that is not a member, and the type is equal if their names are equal in C ++ (names are some distorted form of related types) / p>

Application:

It would be wrong if the "nested" and "nested" in another database were different. This is a structure, not a typedef or usage (which are limited)

GCC will whine if something is ambiguous, try with -pedantic if you want to make it a bitch, even if it isn't. I see no reason why this should be rejected, even if the GCC is simply permissive.

0
source share

All Articles