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

    <tr>
        <th>Summary</th>
        <td>
            clang++ wrongly accepts direct-list-initialization of an enum class from a variable of another enum class type
        </td>
    </tr>

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

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

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

<pre>
    Example:

```
enum class A : int {
    a
};
enum class B : int {
    b
};

int main() {
    A a{};
    B b{a}; 
}
```

P0138 added this language to the standard for C++17 (see: https://eel.is/c++draft/dcl.init.list#3.8)

> if T is an enumeration with a fixed underlying type ([dcl.enum]) U, the
> initializer-list has a single element v, v can be implicitly converted to U,
> and the initialization is direct-list-initialization, the object is
> initialized with the value T(v) ([expr.type.conv]);

However, in the example above, values of type A cannot be implicitly converted to values of type int, since scoped enums do not support that implicit conversion. So the P0138 language doesn't apply here, and the initialization of the variable b should be rejected, as is done by GCC 12.

Note that initially, I filed the same test case as a rejects-valid bug with GCC: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106357
The GCC developers marked that bug as invalid and reasoned that GCC was correct to reject the test case using the explanation I provided above.

See this Compiler Explorer link: https://godbolt.org/z/sYWzcT4s3
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9Vctu4zYU_Rp5cxFBD1uyF1rETqadTVFgUhSzKijxymaHJgWSsuN8fe8lPXl3AkEmxfs45_CQ6a28dPeP4jhpzOrbrLjLip_vprg-cYpmPsKghfdwCxQKygTI2m1aBfoT17z2Lqu3H5K2nyf1H5PSmyOPQpmsWmfV5m3SLfWi-asc_rqlYu1WpM_wUvczNun9Z1HWaxBSooRwUB60MPtZ7BGCpQ8IPggjhZMwWge7rNrSU7ZAmDyyXnAIYfIsXPWFHkSdK0-DIYVKJ8ZAUznQd6NCrpWneV3nzOm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