Open
Description
The following snippet works on MSVC and GCC, but fails to compile fnTemplate
under Clang -- https://godbolt.org/z/KvjTqarxa:
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 makesInner
not an aggregate type