Issue 140596
Summary Aggregate deduction broken in function templates
Labels new issue
Assignees
Reporter snarkmaster
    The following snippet works on MSVC and GCC, but fails to compile `fnTemplate` under Clang -- https://godbolt.org/z/KvjTqarxa:

```cpp
struct Inner {
  // Clang works if you comment this
  Inner() = default;
};

template <typename T>
struct WantsCTAD {
  T t_;
};

auto fn() {
    WantsCTAD ok{.t_ = Inner{}};
    (void)ok;
}

template <typename>
void fnTemplate() {
 // error: no viable constructor or deduction guide for deduction of template arguments of 'WantsCTAD')
    WantsCTAD bad{.t_ = Inner{}};
 (void)bad;
}

int main() {
  fn();
  fnTemplate<int>();
  return 0;
}
```

I'm a bad language lawyer, so I can't say with confidence whether Clang or GCC/MSVC are out of compliance here, but ... it's surprising and inconsistent that this behavior is contingent on both of these:
 - asking for CTAD in a function template (rather than just function)
 - adding a user-declared ctor to `Inner` -- IIUC as of C++20 this makes `Inner` not an aggregate type

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to