I'm wondering why the following code runs just fine in gcc
#include <iostream>
using namespace std;
template<typename T>
struct F {
static T const value;
};
template<>
struct F<int> { // Specialization
static int const value;
};
template struct F<int>;
template<typename T>
T const F<T>::value = sizeof(T);
template<>
int const F<int>::value = 42;
int main() {
struct F<int> ma;
cout << ma.value;
return 0;
}
while on MSVC 2012 I cannot get it to compile:
#include <iostream>
using namespace std;
template<typename T>
struct F {
static T const value;
};
template<>
struct F<int> { // Specialization
static int const value;
};
//template struct F<int>; // error C2950: 'F<int>' : cannot explicitly instantiate an explicit specialization
template<typename T>
T const F<T>::value = sizeof(T);
//template<>
//int const F<int>::value = 42; // error C2998: 'const int F<int>::value' : cannot be a template definition
int main() {
struct F<int> ma;
cout << ma.value;
return 0;
}
From what I read in n3242 §14.7 5
both an explicit instantiation and a declaration of an explicit specialization shall not appear in a program unless the explicit instantiation follows a declaration of the explicit specialization.
and I believe this is the case. Am I missing something?