Find the reason: why not an compilation error?

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;
}
Your main after macro expansion:

1
2
3
4
5
6
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.
Many thanks!
CompilationError<condition>(ERROR##message());

can be changed to:
1. CompilationError<condition>{ERROR##message()};
or
2.CompilationError<condition> temp = ERROR##message();
Topic archived. No new replies allowed.