Visual Studio 2013 (update 2) throws a compile-time error when compiling a template function who's return type is a nested type name, which has been hidden through multiple inheritance, and made visible again with the using
keyword; as in the following code:
struct Base1
{
typedef int value_type;
};
struct Base2
{
typedef double value_type;
};
struct Derived : Base1, Base2
{
using Base1::value_type;
};
template<typename T>
typename T::value_type nullary_function() { return 0; }
template<typename T>
typename T::value_type unary_function(T t) { return 0; }
int main()
{
nullary_function<Derived>(); // Error: C2770
unary_function( Derived() ); // Error: C2893
return 0;
}
(The error numbers vary depending upon whether the function accepts template arguments or not as shown in the comments.)
G++ 4.7 accepts this code.
Specifically, I would like to know what the C++ standard has to say on the matter and whether or not this is a VC++ compiler bug. (It would appear to me that it is seeing as making nested types visible with the using
keyword makes them visible in every other situation as far as I'm aware.)
I am also aware that the line with the using
keyword may be changed from
using Base1::value_type;
to
typedef Base1::value_type value_type;
in order to get the code to compile and function correctly, but it seems bad for portability for some (potentially) valid code to compile on some compilers and not others - hence the desire for clarification.