Specialization pattern static member in different namespaces

There is a template class in the namespace

namespace N
{
    template <typename T>
    class Foo {
        static const T bar;
    };
}

      

And specialization in a different namespace:

namespace O
{
    typedef N::Foo<int> Baz;

    template<>
    const int Baz::bar = 1;
}

      

This code compiles with gcc (4.9.2), but will not compile with msvc (v120):

error C2888: 'const int N::Foo<int>::bar' : symbol cannot be defined within namespace 'O'

      

If I understand this correctly, the code is not C ++ 11 compatible:

Explicit specialization is declared in the namespace that encompasses the specialized pattern. Explicit specialization with identifier-identifier is not qualified, declared in the closest private namespace of the template, or, if the namespace is inline (7.3.1), any namespace in its enclosing namespace.

Is this a compiler error or am I misunderstanding?

+3


source to share


1 answer


This is a compiler error and is still present in HEAD . Please report it. Klang provides a clearer diagnosis:



error: cannot define or update "bar" here because namespace "O" does not include namespace 'Foo'

const int Baz::bar = 1;
          ~~~~~^

      

+7


source







All Articles