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

    <tr>
        <th>Summary</th>
        <td>
            [Clang] Undefined behaviour involving unsequenced side effects on a memory location during constant evaluation should not compile
        </td>
    </tr>

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

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

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

<pre>
    The C++14 code below compiles, but should not, as the constant expression contains undefined behaviour:

```cpp
constexpr bool ub()
{
 int i = 0;
  i = i++ + i; // UB

  return i==1;
}

constexpr bool b = ub();
```

A core constant expression should not contain an operation that would have undefined or erroneous behaviour ([https://eel.is/c++draft/expr.const#5.8](https://eel.is/c++draft/expr.const#5.8)).

The above code includes undefined behaviour as it contains side effects on a memory location which is unsequenced relative to both another side effect on the same memory location and a value computation using the value of the object in the same memory location ([http://eel.is/c++draft/intro.execution#10](http://eel.is/c++draft/intro.execution#10)).

The compiler output can be viewed at [https://godbolt.org/z/7vz4r5sf1](https://godbolt.org/z/7vz4r5sf1).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVNuSmzgQ_Rrx0hUKBBjzwEM8lL9g8wESaox2ZTWrCzPJ128JPGNv4kqqpsoX3Opz1H36uIX3-mIRe9acWDNkIoaZXL_8g9plktT3_q8Z4YXxE-OnsoaRFIJEQ68w0nXRBj3jLyBjAD9TNAoshRQRHsKMMJL1QdgA-LY49F6TTbEgtPUQrcJJW1QgcRarpuhY9ZUVAyvePw_F_hqXZY9shIkMJJGBKBk_Mt7d0tvT_gDaBtDAqgEKVr0HbxG9dwPprVmVHs6Mn-Hb6fFqAIchOptSBlYN5QcPa4fHxJ8qktsdH3V9gN47eYR-hZHcc5Huar7rBcICLehESOdhFgFet5xZrPigJTlA58giRX8XFlI9zWkOYfFJ5K1lRJNrz_h53CVRTkwhxd8Wl29VMV41-ZE1A-PHT2J5x3iXP7adLCUkrbjbSdvRRIVP_ZB8pMPdMl4rBJwmHIMHsiDgildy38HQuAvzOutxBp3YPP4b0Y6owKERQa8IgUBSmEFYCjO6Rz7YVEXw4oq_sAqrQMAqTMTN-DHs8ei1vWyw_Yym7QfJvxOj_g3jfR5_lFTb4CjHNxxjgjJelcV9JJ-DP5_K7T_tgGJYYoBRWJAIq8ZXVCAC_GKhCylJJuTkLoyffzB-btcftWv8VD5zze_SeZdnqq9UV3Uiw75s-aE8FLxusrmf6rY9YHVQjZzaCjtEqcpjXRXI27HjPNM9L3hddCUvD03Lq7zE9lhPh4LjkYtOVawu8Cq0yY1Zr-n-THsfsS-LY83rzAiJxm9rkPPRCHthnKeN6PoE-CLjxbO6MNoHf6cIOphtd75siGaAb088rO1KZk1GefTkn62sokug-3pIHtuP_rcetpll0Zn-J7F1mKPMR7oyfk41376-LI6SP5M3kgbJMzcZ1p7_FwAA__99sPGr">