Question

I've run into a strange issue with using type aliases and nested classes/scopes. The following code is happily accepted by clang 3.3, but rejected by nuwen MinGW 4.8.1:

template<typename T>
struct container
{
};

struct Outer
{
    using type_t = int;
    struct Inner
    {
        using container_t = container<type_t>;
        using type_t = Outer::type_t; //error in MinGW
    };
};

The generated error with gcc: http://ideone.com/cba6Fp (matches the error on my system)

To fix the error in MinGW, you simply move the definition of container_t to after type_t (which makes sense, and is what I should have done originally) - however my question is why does this compile with clang and not MinGW? Is the code valid or invalid?

Was it helpful?

Solution

The issue is in 3.3.7/1 [basic.scope.class]:

2) A name N used in a class S shall refer to the same declaration in its context and when re-evaluated in the completed scope of S. No diagnostic is required for a violation of this rule.

You use the name type_t in Inner, but before the declaration of Inner::type_t. So the name refers to two different declarations, violating the rule.

No diagnostic is required so clang isn't technically nonconforming, but an error would be nice here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top