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

    <tr>
        <th>Summary</th>
        <td>
            Failed Template Deduction in C++20 Designated Initializers
        </td>
    </tr>

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

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

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

<pre>
    Tested with clang 14.0

When a template field is initialized via designated initializers, clang fails to deduce the final specialization.

Code example:
```cpp
template<typename T>
struct Foo {
    int foo;
    T bar;
};

int main() {
    constexpr auto foo = Foo {
        .foo = 1,
        .bar = +[]() { return 5; }
    };

    constexpr auto eval = foo.bar();
    
    return 0;
}
```

Note that this works succesfully in MSVC and GCC:

MSVC: https://godbolt.org/z/qr5a56xbs
GCC: https://godbolt.org/z/sqc4r1Eb4
clang: https://godbolt.org/z/P1c3v7Gfj

The compiler reports:
```
x86-64 clang 14.0.0 - 358ms

<source>:8:26: error: no viable constructor or deduction guide for deduction of template arguments of 'Foo'
    constexpr auto foo = Foo {
                         ^
<source>:2:8: note: candidate function template not viable: requires 1 argument, but 2 were provided
struct Foo {
       ^
<source>:2:8: note: candidate function template not viable: requires 0 arguments, but 2 were provided
1 error generated.
ASM generation compiler returned: 1
<source>:8:26: error: no viable constructor or deduction guide for deduction of template arguments of 'Foo'
    constexpr auto foo = Foo {
                         ^
<source>:2:8: note: candidate function template not viable: requires 1 argument, but 2 were provided
struct Foo {
       ^
<source>:2:8: note: candidate function template not viable: requires 0 arguments, but 2 were provided
1 error generated.
Execution build compiler returned: 1
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztVkuP2zgM_jXKhZjAbycHH2aSSdFDiwINds-yTCdqFcujRybTX1_KzrNTzC4K9NQatmKTIvmR4iO1bl6qNVqHDTxLtwWheLeBOJtGLFqy6H5c_91iBxwc7nrFHUIrUTUgLchOOsmV_Ebye8mhQSs3HQ_qLixjWbI4am65VBacpp2NFwhuG7R1XIHtUQz7uZO6m16bX-gGAQ-crCNLj0RWROMt-n6knOCxdOFeeuz4DmHN0seRa53xwsFKa2Dlw0gDumTnoNWapVe0NdTcnCmsXF7ehzXI7LjsWDJjyfxWn9AdhfPQG-Ce_GyDvXT52m64piduTBH6gUUIBhZLHlhO9_JiDAw6bzrICRYEdGfJ11B_Agn3FO6gmqwHM6PimwBc3o6mopto3B7AtbmP2oVD5Y4Wyo9nbb5asF4ItK1X6oXCDR8-_7MA3jXwbrG4HOewBhaRYOtcbwMvWdG90U2tlZtqs6Gvb_Q8mZznxaG2o9io6D-l7JPITPxYZ6PUkJH_R-5TLNJ9-a79cg11TZkr9K6XCg1FqdfG2dfJOX4eZsVdkV0V1zSCO0jz2c5eq6TEtdobgSFp0_sZPUkRAKIx2oSXTocyqxWOZxoyWhugeyinUDiw8ZKqpb2h6fZSu9xs_A47ZwOVJSUlJq2_lr-vLpY__tSV5OgOORDq8x4Enb9shl7iuxHkGSHtOXoZdhp88tKghfgMPbST2jtI4BkNQm_0nnxu3q7z34wuugT2TXjxeJiwwQ5NaJTHTnf_-cOJFsxdZVaoP5ImY_HfNPnT0-TxgMIPlmovaQa_mSenJjRpqrSZp3M-cdIprFY0hGlCr09Yl-cMoO68CAMneUgiIp-H-furYT7xRlU_tEz66-DrKYGhD6X2p587cuoLCjqJlbTWI_m8yot0nk22VSmQzzHLm3aW84iLEqMsTgvkqRDNrIwniteobDUOv4mskihJojLKkzRN43SKSVHU0SzK5nlZ1m3LsghpJqtpMBya98RUA4babywxlbTOXpjcBucQT_opi7faVDturOPy62TAWw1gvwM0uMa5">