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

    <tr>
        <th>Summary</th>
        <td>
            Integer value out of range for enumeration type causes hard error rather than SFINAE
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          improbable-nickkrempel
      </td>
    </tr>
</table>

<pre>
    For example, compiled with clang trunk with `-std=c++20` ([godbolt](https://gcc.godbolt.org/z/PsYofabMb)):

```
#include <iostream>

enum Enum { A, B, C };

template <int V, Enum X = static_cast<Enum>(V)>
constexpr bool test(int) {
    return true;
}

template <int V>
constexpr bool test(...) {
    return false;
}

int main() {
    std::cout << test<4>(0) << '\n';
}
```

Results in an error:
```
<source>:7:27: error: integer value 4 is outside the valid range of values [0, 3] for this enumeration type [-Wenum-constexpr-conversion]
template <int V, Enum X = static_cast<Enum>(V)>
```

(Adding the compiler flag `-Wno-error=enum-constexpr-conversion` avoids the error, but then gives the wrong result: `1` rather than `0` is output.)

This contrasts with other undefined behavior: for example, changing the 5th line to `template <int V, int X = V * V>` shows that signed integer overflow is not a hard error but is SFINAE-able.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVE2P2zgM_TXKRYjhj9hJDj44yQzQwy4W28W0PRWyTNvqKFIgyZm2v35JK-lks52eGii2RZF65OOTWtt9qx-t4_BVHE8aWL7n0h5PSkPHX1QYudTCDDy4yTxHA6vSpQ8dKw6S5TsceYomzvINK3eD7VqrAysPOB9DOHlWNCx_xDFImVyWE-sGtHzH_1_-k-1F-0fL8i0N9E4PLL0-q_Qy4jQvlJF66oCzYq-sDw7EkRUPtzFgpiN_oAdb73hDFe3oscf5gRW7W98AWLQIcTsT-BM5zrEf0XTgPoig5GcpfEAPWiCwfPM0p3qBldb4AF9PjrfWah4AnfMNbodOlEP04vh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