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

    <tr>
        <th>Summary</th>
        <td>
            [clang] Accepting invalid C++ code with multiple designated initializers for a union
        </td>
    </tr>

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

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

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

<pre>
    ## Code to Reproduce
This is an excerpt from [[dcl.init.aggr] p13](https://eel.is/c++draft/dcl.init.aggr#example-13) (with a redundant `union` for C compatibility):
```cpp
union u { int a; const char* b; };
union u g = { .a = 1, .b = "asdf" };  // error
```
## Actual Output
In C and C++ mode, the produced warning is: (https://godbolt.org/z/7z5Ed58qc)
```
<source>:2:23: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
union u g = { .a = 1, .b = "asdf" };  // error
                      ^~~~~~~~~~~
<source>:2:20: note: previous initialization is here
union u g = { .a = 1, .b = "asdf" };  // error
                   ^
```
## Expected Output
I assume that this code is allowed in C99. However, in C++ mode, such code is disallowed:

> When a union is initialized with an initializer list, there shall not be more than one explicitly initialized element.

\- [[dcl.init.aggr] p20](https://eel.is/c++draft/dcl.init.aggr#20)

## Suggested Fix
Disallow this code entirely in C++ mode, or emit an additional warning which informs the user that they are using C99 extensions.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vc2O4zYMfhrmQsRwZHsSH3LIL9pTgbbAnmWJsVnIkivJSWYOffZCTjqZzO720mKNBFbIkCI_fiRlCNxaojVUW6j2MznGzvn1gQPZizzTrHH6dQ2iAFHgzmnC6PBXGrzToyLI95Bvfu84IAeUFumqyA8RT971OLncamUythwz2bYeqj0OiwKqPYhVF-MQoNiAOII4EpmMA4ijArEFsdVeniKI47O9KOgq-8HQfFGAqBHE6sKxQ4me9Gi1tBHhJR8tOwsvOZ6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