There is a template class in a namespace
namespace N
{
template <typename T>
class Foo {
static const T bar;
};
}
And a 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 fails to 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 compliant:
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.
Is this a compiler bug or do I misunderstand?
Aucun commentaire:
Enregistrer un commentaire