template<bool>
class CompilationError;
template<>class CompilationError<true>
{
public:
template<class ...Args>
CompilationError(Args...) {}
};
#define STATIC_CHECK(condition, message)\
{\
class ERROR##message{};\
CompilationError<condition>(ERROR##message());\
}
int main()
{
STATIC_CHECK(true, right);
STATIC_CHECK(false,wrong);//An compilation error was expected, but it can go through the compiler
return 0;
}
int main()
{
{ class ERRORright{}; CompilationError<true>(ERRORright()); };
{ class ERRORwrong{}; CompilationError<false>(ERRORwrong()); };
return 0;
}
The compiler is treating CompilationError<false>(ERRORwrong()); as a function declaration of a function named ERRORwrong that takes no arguments and returns an object of type CompilationError<false>. The function is never called so it doesn't complain about things not being defined.