From the description on cppreference I assumed that if constexpr
would behave like a normal if
but works at compile time.
The description says:
In a constexpr if statement, the value of condition must be a contextually converted constant expression of type bool. If the value is true, then statement-false is discarded (if present), otherwise, statement-true is discarded.
constexpr (false)
is obviously false, so the static_assert should be discarded, right? However, with the following code I always get a compilation error for the assertion:
if constexpr (false) {
static_assert(false, "empty");
}
while I expected no compile error. This is XCode 10 with clang and C++17 enabled. Is that a problem of the compiler or is it me misunderstanding this concept?
By request (even though I think it's not relevant here): the compiler error I get is:
Static_assert failed "empty"