次のコードが 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;
}
MSVC 2012ではコンパイルできません:
#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;
}
n3242 §14.7 5 で読んだことから
明示的なインスタンス化と明示的な特殊化の宣言の両方が、明示的なインスタンス化が明示的な特殊化の宣言に続く場合を除き、プログラムに現れてはなりません。
そして私はこれが事実だと信じています。何か不足していますか?