Clang emits -Winteger-overflow warnings from discarded if constexpr #59448
Open
Description
Testcase: https://gcc.godbolt.org/z/ds4M6zah4
#include <limits>
int main() {
using Bounds = std::numeric_limits<long>;
if constexpr (sizeof(long) < sizeof(long long)) {
const long long longMaxPlusOne = static_cast<long long>(Bounds::max()) + 1;
const long long longMinMinusOne = static_cast<long long>(Bounds::min()) - 1;
}
}On Unix x86-64, long has the same size of long long, so the if constexpr branch is discarded as the condition is false. However clang warns:
<source>:6:80: warning: overflow in expression; result is -9223372036854775808 with type 'long long' [-Winteger-overflow]
const long long longMaxPlusOne = static_cast<long long>(Bounds::max()) + 1;
^
<source>:7:81: warning: overflow in expression; result is 9223372036854775807 with type 'long long' [-Winteger-overflow]
const long long longMinMinusOne = static_cast<long long>(Bounds::min()) - 1;It's a bit interesting that other kind of warnings are instead suppressed. For instance, if one adds a 123 / 0 outside of the if constexpr, Clang warns about the division by zero, but it doesn't if the division happens inside the if.
Activity