template <int answer> struct Hitchhiker {
static_assert(sizeof(answer) != sizeof(answer), "Invalid answer");
};
template <> struct Hitchhiker<42> {};
While trying to disable general template instantiation with static_assert
I discovered that the above code in clang
generates the assert error even when the template is not instantiated, while gcc
generates the assert error only when instantiating Hitchhiker
with a parameter other than 42
.
Fiddling around I found that this assert:
template <int answer> struct Hitchhiker {
static_assert(sizeof(int[answer]) != sizeof(int[answer]), "Invalid answer");
};
template <> struct Hitchhiker<42> {};
behaves the same on both compilers: the assert kicks in only when the general template is instantiated.
What does the standard says, which compiler is right?
g++ 4.9.2
clang++ 3.50
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…