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

    <tr>
        <th>Summary</th>
        <td>
            Clang accepts the undefined behavior operation in a constant expression
        </td>
    </tr>

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

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

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

<pre>
    ````cpp
enum A {a = 0};
constexpr A e = static_cast<A>(1024);
````
According to [expr.static.cast p10
> If the enumeration type does not have a fixed underlying type, the value is unchanged if the original value is within the range of the enumeration values ([dcl.enum]), and **otherwise, the behavior is undefined**.

[dcl.enum] p8 defines the range of the enumeration values, that says
> Otherwise, the values of the enumeration are the values representable by a hypothetical integer type with **minimal** width M such that all enumerators can be represented.  

In this case, it is sufficient to represent the value `0` of the unique enumerator if `M` is `1`. Apparently, the value `1024` cannot be representable in the hypothetical integer type with **minimal** width M. So, the full-expression of the initialization is not a constant expression since the violation of [expr.const] p5
> an operation that would have undefined behavior as specified in [intro] through [cpp];

However, Clang accepts this example without any diagnosis. 

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVMtu4zgQ_Br60hhBDyu2Dzo4yQ42h2AP8wEDimxLvaBJLUnF8X79NkXH9szkMFiAliz1q6q6W73T5048lNejpkmUz6Lco52PsAexeZQgmmcoxeZZNI_ZqJwNEd8nzx64mEOUkdR3JUMUzdNeNH-IeluV9VrUu2vYfaH8Zq-U85rsANGBaB9TziLnKlIumKqLJ2eElwPEESFBQ88-zkI8TwjaYQDrIozyDUHCgd5Rw2w1enNekrOXqJ-W6DdpZgQKbFejtAN7Us7rPA1kpbm5nCiOZBejT67gfkWwOAdguoxfK1Mko2ifE3EuKa1m256P40h_onBF0iPjJeczGI0Hsqizb3Ehna8_5IVpC9k3_A6wXExGCPIcblL-9TOYC41P8kiP9x4eJ48BbZS9YQ5n1ns8T4kcN43FIxtxQJ87kwS80D-SpaM0-YENmi2vEGY1ZnzSmGtZ5wMoaVmhWznUBcC9LC-pMZQcMwuKScgwHw6kiAPSSF2j71rPw5cG8IPqbOmfGe9Kp3Fg-2vy4YR8q_hXwH6aWAobzfnHUUoOadDZnTGnMbyHvah0maH_r1MB39xH1cNszJe0KBhC6s-FB4dFkob-zV2jvBESll2VrMBdSCCrLk0lZ3IAp_lYwCVkGbX2NjHcDjdd1y517ORmo_POXcf3NtSSezGhogOlDbMpOVP2LuWNo3fzMKZ36YPT3r4s-fqnO-Eb-sT4yfB8g1QKpxhyw_FdHieTRXMzc7Rn0CQH6wKF4jIjK901etfs5CpSNNj9nOdTzDeCDPhT6VazN90Y4xREww36ymdgGHPPoh35wZi3j9uXybu_UUV-pBCWVfzaPrT1djV2_a7a6qrRuMZS7frddldj-9Cse1miXuNmZWSPJnQskKhriydYUvB_FmtFXV3Wdbmp1lVdNe2m6LXa9nVVY_2gd9WhFOsSj5JMkXAUzg8r3y2Q-nkIbDQUYrgZJVMbLOJSjvPLmYX13ftxLNuqWi2luwX6fwakDS0">