Consider the following code, which has an unreachable call to undefinedFunction
.
void undefinedFunction();
template <bool b = false>
void foo()
{
static_assert(b == false);
if (b)
undefinedFunction();
}
int main()
{
foo();
}
GCC compiles and links this without complaint. With the static_assert
, it's hard to see how the compiler could do anything different, but does the standard have anything to say about this? What if the static_assert
is removed? Is the compiler at all obligated to remove the branch or can it actually emit an unreachable call instruction that will cause the linker to complain?