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

    <tr>
        <th>Summary</th>
        <td>
            designated initializer of template class rejected by clang
        </td>
    </tr>

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

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

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

<pre>
    The following code is rejected by clang but accepted by gcc and MSVC with `-std=c++20`:

```c++
template <typename T>
struct Foo {
    T x;
};

template <typename T> auto tst(){
    auto foo=Foo{.x=0};
    //auto foo=Foo{0};
    return foo;
}

int main()
{
    auto res=tst<int>();
}
```

It seems that in the instantiation of `foo`, the template argument `T` of `Foo<T>` could be deduced to `int` according to the type of `Foo::x`, while clang complains about the deduction failure of `T`:

```c++
<source>:7:14: error: no viable constructor or deduction guide for deduction of template arguments of 'Foo'
    7 |     auto foo=Foo{.x=0};
      | ^
<source>:14:14: note: in instantiation of function template specialization 'tst<int>' requested here
   14 |     auto res=tst<int>();
      |              ^
<source>:2:8: note: candidate template ignored: couldn't infer template argument 'T'
    2 | struct Foo {
      |        ^
<source>:2:8: note: implicit deduction guide declared as 'template <typename T> Foo(int) -> Foo<T>'
<source>:2:8: note: candidate template ignored: could not match 'Foo<T>' against 'int'
<source>:2:8: note: implicit deduction guide declared as 'template <typename T> Foo(Foo<T>) -> Foo<T>'
<source>:2:8: note: candidate function template not viable: requires 0 arguments, but 1 was provided
<source>:2:8: note: implicit deduction guide declared as 'template <typename T> Foo() -> Foo<T>'
1 error generated.
```

It's also worth noting that using `auto foo=Foo{0}` does not trigger any error.

[https://godbolt.org/z/d3ccWsjWa](https://godbolt.org/z/d3ccWsjWa)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vk2P4jgQ_TXFpdTIsSGBQw40DNIe9rKLds6OXSQeBZu1nf6YX7-yA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