Extending temporary's lifetime through rvalue data-member works with aggregate, but not with constructor, why?
问题 I've found the following scheme to extend a temporaries lifetime works, I don't know if it should, but it does. struct S { std::vector<int>&& vec; }; int main() { S s1{std::vector<int>(5)}; // construct with temporary std::cout << s1.vec[0] << '\n'; // fine, temporary is alive } However, when S is given an explicit value constructor it is no longer an aggregate, and this scheme fails with an invalid read on s1.vec[0] struct S { std::vector<int>&& vec; S(std::vector<int>&& v) : vec{std::move(v