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

    <tr>
        <th>Summary</th>
        <td>
            Integer overflow resulting from negation shows wrong value in diagnostic
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:diagnostics
      </td>
    </tr>

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

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

<pre>
    ```c++
constexpr int A = - (1 << 31);
```

gives this output:

```console
<source>:2:15: error: constexpr variable 'A' must be initialized by a constant expression
constexpr int A = - (1 << 31);
              ^   ~~~~~~~~~~~
<source>:2:19: note: value 2147483648 is outside the range of representable values of type 'int'
constexpr int A = - (1 << 31);
 ^
```

The diagnostic shows the value `2147483648`, which is simply `(1 << 31)`. That value is fine however. The problem only occurs when we try to negate the value, so the diagnostic should show the negative value of `-2147483648`.

GCC manages to print the correct value: https://godbolt.org/z/bb1Gjfdcx
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVMGO4ygQ_ZrypdSRDbHjHHzIpDujvc8PAC7bjAhlAU4mc9hvX-H2bLpH2j0MQiGAX9V7r0qoGO3oiTqov0D9WqglTRy6pBX1FEKhuX900JTv04D4kmf5CuXJsI-JfswBrU94QpCv-IIg2gpBnkGeUVYgjiC37_-Nsm3X39HeKGKabERe0rwkkKeP98_U7CM72k7lOfISDIF8A3kSIE9VDfKEFAKH_OdJ7qaCVdoRgjicQBzwusSEmtB6m6xy9if1qB-o3jHKJ8w4itGy_zOl-GlA_YaIfz_Hf2s4ZuqeE-X1ptxCKKr9Yd_KZt_iu0fR9oRpIgzKj4Q8YKBMl3xaZa6wmM_TY15VW59AHP5QCtRv_1O-bxNhb9XoOSZrME58jyu5d_LQlE_-GSrOeJ-smbKWaK-ze-B6_Hv6ptzht0mlLY6NOFhPOPGdbhTyHeEcWDu6Inv3QDZmCRHvE3m8E6bwwMToaVSJnoRy_sjr_jPrxfUr-fVqRdnbLxE8ZI4vn4TsPprw9XzGq_JqzJ3MOIdsbQ5kOAQym4hc0imlOeYOFxcQl5F7zS7tOIwgLj9BXLSuvn4fevOj6DvZH-VRFdRVTSuqRshSFlPXtHV7kK0-tEMpjenNIHS9V3Upe6G0bArbiVLIci9EVVWtkDtdD3VtDjQ0pd4PZGBf0lVZt3Puds25CxvjQl0jxLEtnNLk4voaCGGc8iPI09OrCELkZyJ0Gf2ilzHCvnQ2pviMl2xy1P3lE40UkG8UBsd3DBQXl6wfcQh83VxmvzXNPbAff5XbfyhPsQTX_WacTdOid4avIC457ba8zIG_k0kgLqumCOKyyvonAAD__18Pf6I">