2.4.7 static_assert
Name
static_assert
Description
compile-time assertion. It verifies a constant expression during compilation; if the condition evaluates to false, the compiler stops and generates a build error.
Remark
Examples
EX1
static_assert ( sizeof(int) == 4); // pass, no message static_assert ( sizeof(int) == 4 && 2 > 1, "pass 1"); // pass //static_assert ( sizeof(int) != 4, "fail 1"); // should fail
EX2
#define MY_CONST 4 void test() { //static_assert (MY_CONST != 4, "fail 2"); // should fail }
EX3
int test_int() { return 4; } //static_assert ( test_int() == 4); // should not compile, because the expression is not compile-time constant