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

    <tr>
        <th>Summary</th>
        <td>
            -Wenum-constexpr-conversion should be a hard error, not a warning
        </td>
    </tr>

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

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

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

<pre>
    The `-Wenum-constexpr-conversion` warning was created to account for the fact that casting integers to enums outside of the valid range of the enum is UB in C++17. Constant expressions invoking UB lead to an ill-formed program.

The current behavior of Clang is that it does warn and it does error, but the message is nevertheless a warning that the user can easily suppress via `-Wno-enum-constexpr-conversion`.

Since the program is **ill-formed**, I don't think this should be a warning that can be disabled. Just like one can't disable the warning in this ill-formed code:

```cpp
constexpr int x[10]{};
constexpr int y = x[10];
```

Therefore I propose to make the diagnostic a hard error that cannot be disabled. Additionally, this "hard error" behavior should only be active in C++17 (it's currently active in for any standard).

The warning could be repurposed to be a general warning that one can enable, and is active not only in `constexpr` expressions, but in any expression that involves casting an integer to an enum.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9VMuu4ygQ_Rq8QYls3ImThRc3ia7UvZ0ZzRpDxaYvAQtwuu98_VThOI-eUUvIDyiKc-qcovP6s_1zAM625epvcNNlpbyLCX6Ogb6uEKLxDlf5DxmccT2-I1cBZALNk-dSKT-5xM8-8ISJzlIl_JCJKxkTbTAuQY95KJpOiNxPKRoN3J_zlqu0RvMgXX-fojhuIv_rgNv5kYkDjqpZ8yOhk3geIYRI4CKGXP0HHYXhFuSMy3Fj7QphXRDoGHwf5GXNyhMr3-Yn0VZTCIDZOhjk1SAFPP9oJaGOMwuTuPYQM31Mqu8TEIIPTBx5N6WM-YJwJFLAnQ6wcDhncYrLe-lyQgqdIgSsj-Mgo7GfPE5j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