Hi folks,
Look at the following example code:
template<typename>
class Base
{
typedef int ValueType;
};
template<typename ValueType>
struct Derived : public Base<ValueType>
{
Derived(ValueType);
};
Derived<float> obj(1);
This code compiles cleanly with GCC 4.7.2 and Clang 3.5 (Xcode 6.2).
However, it fails to compile with Visual Studio 2013, complaining that it cannot access private typedef "Base<ValueType>::ValueType".
Furthermore, if you make the private typedef public:
template<typename>
class Base
{
public:
typedef int ValueType;
};
It compiles on all three compilers, but the produces different answers.
GCC and clang result in ValueType=float in the Derived constructor definition, whereas Visual Studio 2013 results in ValueType=int in the Derived constructor definition.
What does the standard say should happen in these cases? Which compiler(s) are closer to implementing the standard behavior?
The standard is clear (see C++11 section 14.6.1 paragraph 9) about what happens when "Base" is not a template, but it seems more vague about when "Base" is a template (which the example above seems to demonstrate).
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 403 |
Nodes: | 16 (2 / 14) |
Uptime: | 97:18:54 |
Calls: | 8,446 |
Calls today: | 2 |
Files: | 13,181 |
Messages: | 5,908,180 |