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

    <tr>
        <th>Summary</th>
        <td>
            Wrong codegen for overload set with aggregate designated initializers and anonymous union
        </td>
    </tr>

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

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

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

<pre>
    ```c++
struct C {
  union {
    int a;
    const char* p;
  };
};
struct D {
  int a = 1;
  const char* p = "bad";
};
int f(C);
int f(D);
int i = f({.a = 2, .p = "ok"});
```

clang should either reject as ambiguous, or remove `f(C)` from the overload set under https://wg21.link/dcl.init.aggr#4.1.sentence-2 and call `f(D)` with a `D{.a = 2, .p = "ok"}` (the standard is not particularly clear on this; this came up discussing [CWG 2169](https://wg21.link/cwg2169)).  It should not call `f(D)` with a `D{}` (i.e. `D{.a = 1, .p = "bad"}`), but that's what it does.

Also, it comes up with a comedy warning:
```c++
warning: ISO C++ requires field designators to be specified in declaration order; field 'p' will be initialized after field '' [-Wreorder-init-list]
<source>:13:20: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
int i = f({.a = 2, .p = "ok"});
                   ^~~~~~~~~
<source>:13:17: note: previous initialization is here
int i = f({.a = 2, .p = "ok"});
 ^
```

If you remove the declaration `f(C);`, it DTRT.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVU2P4zYM_TXMhYhhy7EdH3zIx6SYU4F2gTnLEmOrq0ipPmYwPfS3F3IyiTPb3T2sYUSRSD2-J5E0914NhqiDagvVfsFjGK3rSPBwim7RW_neQZ1fXgFsm958D_nGBxdFwB1Cc11BjEZZM19AVCYgh3K2IqzxAcXIHbANnmc2aPa32fz_NdR-jjzhIpR7LGYIn7AnOzDWcwmM_S92wjkCW--Atd8s7j8vqgkxmaDZZpf4DNgOs1ss-zWF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