I am surprised by the following compiler error:
template <typename T>
struct A
{
A(T t): t_{t} {}
T t_;
};
struct S
{
};
int main()
{
A<S> s{S{}};
}
The error is (with clang):
test.cpp:4:16: error: excess elements in struct initializer
A(T t): t_{t} {}
^
test.cpp:15:10: note: in instantiation of member function 'A<S>::A' requested here
A<S> s{S{}};
^
GCC gives a similar error.
I would expect the expression t_{t} to try to copy construct t_ from t. Since S has an implicitly generated copy constructor, I wouldn't expect this to be a problem.
Could someone explain what is going on here?