<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59448>59448</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang emits `-Winteger-overflow` warnings from discarded `if constexpr`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          dangelog
      </td>
    </tr>
</table>

<pre>
    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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VU1v4zYQ_TX0ZWBDIi2JPuhgO2u0h2B7aNFjQJEjia1MGhwqdvLrC8rKxvloD4ugQUDb5HDemzePpCKynUOsWbFjxd1CjbH3oTbKdTj4btF481T_jhS1ImRiC32MJ2Jiy_iB8UOn9arzpvFDXPnQMX54ZvxgaH1fPqt-zbI7lm3nsczm_-tPLqzTw2gQmNgP9mgjMfHtdod1EY7KOsYl4xtg1e46DwAwknUd7PzoDAETd0DRJFZi68Yj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