Issue 178879
Summary [Clang][C++20] CTAD on aggregates fails with designated initializers in function templates
Labels clang
Assignees
Reporter Attacker23
    ### The following code is rejected by Clang but accepted by GCC, EDG, and MSVC.
https://godbolt.org/z/We8WMz7vo

```cpp
template<typename T>
struct A { T i, j; };

template<typename T>
void foo ()
{
  A a = { .i = 1, .j = 3 };
}

int main ()
{
  foo<int>();
}
```

### Output:
```
<source>:7:5: error: no viable constructor or deduction guide for deduction of template arguments of 'A'
    7 |   A a = { .i = 1, .j = 3 };
      |     ^
<source>:12:3: note: in instantiation of function template specialization 'foo<int>' requested here
   12 |   foo<int>();
      | ^
<source>:2:8: note: candidate template ignored: couldn't infer template argument 'T'
    2 | struct A { T i, j; };
      |        ^
<source>:2:8: note: implicit deduction guide declared as 'template <typename T> A(int, int) -> A<T>'
<source>:2:8: note: candidate function template not viable: requires 1 argument, but 2 were provided
    2 | struct A { T i, j; };
 |        ^
<source>:2:8: note: implicit deduction guide declared as 'template <typename T> A(A<T>) -> A<T>'
<source>:2:8: note: candidate function template not viable: requires 0 arguments, but 2 were provided
<source>:2:8: note: implicit deduction guide declared as 'template <typename T> A() -> A<T>'
1 error generated.
Compiler returned: 1
```
### The following code is accepted by all compilers; Clang has accepted it since version 17.0.1 (as a result of the fix for issue #83368).
https://godbolt.org/z/qEja4afzo
```cpp
template<typename T>
struct A { T i, j; };

int main ()
{
  A a = { .i = 1, .j = 3 };
}
```

I believe this is a rejects-valid bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to