Since there's been no quote yet, I've been playing around with your example:
Both gcc 4.5.1 and Clang 3.0 accept the code as can be seen below.
Now, we just need someone to dig out an authoritative answer. With Clang, gcc and VC++ agreeing though (not that frequent), it seems intended.
On ideone (4.5.1):
#include <utility>
struct A
{
struct Gold {};
};
struct B : public A
{
typedef Gold BaseGold;
struct Gold {};
};
struct C : public B
{
typedef Gold BaseGold;
struct Gold {};
};
static_assert(std::is_same<B::BaseGold, A::Gold>::value, "Not the right treasure!");
static_assert(std::is_same<C::BaseGold, B::Gold>::value, "Not the right treasure!");
On Clang:
#include <stdio.h>
template <typename T, typename U>
struct is_same { enum { value = false }; };
template <typename T>
struct is_same<T,T> { enum { value = true }; };
struct A
{
struct Gold {};
};
struct B : public A
{
typedef Gold BaseGold;
struct Gold {};
};
struct C : public B
{
typedef Gold BaseGold;
struct Gold {};
};
int main() {
if (!is_same<B::BaseGold, A::Gold>::value) {
printf("oups");
}
if (!is_same<C::BaseGold, B::Gold>::value) {
printf("oups");
}
}
Clang output (as expected):
define i32 @main() nounwind readnone {
entry:
ret i32 0
}
Gold
has two meanings inside the derived type, first it is used in thetypedef
to refer to the type enclosed in the base class, and then redefined to be a local type. I assume that the behavior in VS2010 is that it allows it, get's the intended type in the typedef but the name is then reused for the type enclosed in the derived type. I am quite sure this is incorrect, but I haven't found the quote from the standard yet. – Pyretypedef A::Gold BaseGold;
and then the question just goes away? – Vaporimeter