不同命名空间中的模板特化静态成员

Template specialization static member in different namespace

命名空间

中有一个模板class
namespace N
{
    template <typename T>
    class Foo {
        static const T bar;
    };
}

以及不同命名空间的专业化:

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

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

此代码使用 gcc (4.9.2) 编译但无法使用 msvc (v120) 编译:

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

如果我理解正确,代码不符合 C++11:

An explicit specialization shall be declared in a namespace enclosing the specialized template. An explicit specialization whose declarator-id is not qualified shall be declared in the nearest enclosing namespace of the template, or, if the namespace is inline (7.3.1), any namespace from its enclosing namespace set.

这是编译器错误还是我理解错了?

这是一个编译器错误,still present in HEAD。请举报。 Clang 提供了更清晰的诊断:

error: cannot define or redeclare 'bar' here because namespace 'O' does not enclose namespace 'Foo'

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