Q:

Specialization of a template class static member variable when also using 'extern template class' syntax

I have a template class that I only intend to use with 3 different types that I know ahead of time. To reduce code bloat I want to keep as much as possible outside the header. The template class also has static variables that must be different depending on the specialization.
I tried to accomplish that both on Windows with Visual C++ 19.15.26729 and Mac with XCode and clang-900.0.39.2. I needed different code to satisfy each of the compilers, what's worse the compilers complained about each other's "good" versions of the program.
Here is a minimal example:
// A.h
template<typename T>
class A
{
public:
    static T x;
};

// template<> int A<int>::x; // PROBLEMATIC PART

extern template class A<int>;

// A.cpp
#include "A.h"

template<> int A<int>::x = 42;

template class A<int>;

// main.cpp
#include "A.h"

int main()
{
    return A<int>::x;
}

The code above (with the line commented) compiles fine on VC++, but clang complains:
Explicit specialization of 'x' after instantiation
The answer to this question helped: What's the right way to specialize a template when using "extern template"?
With template<> int A<int>::x; uncommented it compiles fine on Xcode, but then Visual C++ complains:
1>A.cpp(3): error C2086: 'T A<int>::x': redefinition
1>        with
1>        [
1>            T=int
1>        ]
1>A.h(9): note: see declaration of 'x'
1>A.cpp(3): error C2086: 'T A<T>::x': redefinition
1>        with
1>        [
1>            T=int
1>        ]
1>A.h(6): note: see declaration of 'A<int>::x'

Is my approach fundamentally wrong? Is it a compiler bug? Maybe it is a feature supported by only one of the compilers, if so - which version is correct according to the standard?

A:

It is indeed a bug in the Microsoft compiler, already logged in their backlog. Follow this issue for updates: https://developercommunity.visualstudio.com/content/problem/319447/explicit-specialization-of-static-data-member-inco.html

