I'm testing the possibilities of if constexpr
and I was wondering if it was possible to remove control flow statements with it.
The code I'm testing is:
int main() {
void *indirect_label;
if constexpr (false) {
goto label; // Rejected by MSVC, clang and GCC
}
if constexpr (false) {
continue; // Rejected by clang and GCC
}
if constexpr (false) {
break; // Rejected by clang and GCC
}
if constexpr (false) {
goto *indirect_label; // Rejected by clang and MSVC
}
return 1;
}
I added a test for the indirect gotos language extension implemented by GCC and clang.
Considering that if constexpr
should discard the statements if the condition is false, why does MSVC and GCC accept some parts of the code (but different) and clang rejects all four.
What behaviour is correct?