<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/147328>147328</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang: compile implicitly an convertion from integral to enum class (error excepted)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jonathanpoelen
</td>
</tr>
</table>
<pre>
With this code:
```cpp
enum class E { a,b,c};
int main()
{
E e;
e = {1};
}
```
Clang 18,19,20 and trunk compile without error.
Narrowing conversion gives a error, but the diagnostic is not appropriate:
```cpp
long long ll = 0;
e = {ll}; // non-constant-expression cannot be narrowed from type
// 'long long' to 'E' in initializer list [-Wc++11-narrowing]
```
Gcc:
```cpp
test.cpp: In function ‘int main()’:
test.cpp:6:9: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘E’ in assignment
6 | e = {1};
| ^
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx0lEuTozgMxz-NuKiSAgMhHDjkubWXvc7ZMWrwrJEpW_RM76ff4pHurpnplCsYgR7_nyx0jLZjogbKM5TXRE_S-9B896yl1zx6csTJw7dvzTcrPUpvIxrfEuQnSJd1SNdlxhHSE_E0oHE6RrwhVGfUoC4PUBcD1RXy8-pkWXDQlkEdQdWzrTojQnpCvCFBfkbcbgkhv86Bsg__6oqfE68hL05zh9kR1CWrQV1UippblDDxv2j8MFpH-MNK7ydBCsGH_er4jw7B_7DcofH8SiFaz9jZV4qo1xdBXfAxCUpP2FrdsY9iDdqI7AX1OAY_BqvlSyjOc4frn1v0pKuSd3HOreoQ1B3UHdnzzniOoll29HMMFJeyjOY55YOQl6qpxZfgB5S3kRZcz98WB1T1nhtUheJn023eWkbLVqx29j8K6GwUhPK8-2ZAnUGds2zHTzJQXn8H_pcxX-kVirKft_kJ_2Z8mdjIXD7cFBxTqI-_9H8z12u8T94HyE-zdetDfnoSWFslHxEhvzyCNrQjNs5Han9TB_ntPdEC4un6yWwZ14kYiGUDekCoLvjHk7ixXh5v-_L2C6mkbfK2zmudUJNVZVan6ngokr7JDlSWlS5VkZlM1aaloiQyZa1K3b685IltVKrKtEqrrCyytNhrnR6ORhd1nuWHXJdQpDRo6_bOvQ57H7rExjhRkxVVro6J0w9ycZlspcw8HqDUPOShmR12j6mLUKQzm_gRQqw4apZpWnhvk2OH0Vljxb2h5if-uafL-bMs1AXtZq6fvgCgjkvjkH4aGoVaUHUyBdf0ImOcu70c085KPz32xg-g7nMh22U3Bv-djIC6L8IiqPum7bVR_wcAAP___Zdkng">