The Branch Nobody Runs

template <typename T>
std::size_t length(const T &v) {
    if constexpr (std::is_integral_v<T>) return 1;
    else                                 return v.size();
}

int main() {
    std::cout << length(42) << length(std::string("abc"));
}

This compiles and prints 13. Now delete the word constexpr, leaving a plain if. What happens?

A

Compiles, but length(42) returns an unspecified value, since the return type is deduced from two incompatible branches.

B

Still compiles and prints 13: the false branch is dead code the optimizer removes before it can matter.

C

length(42) fails to compile, because the else branch is instantiated for T = int and int has no member size.

D

Both calls fail, because a runtime if cannot use std::is_integral_v, which is a compile-time constant.