https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79679
Bug ID: 79679 Summary: [C++17] Missing destruction of temporary within constructor's mem-initializer-list Product: gcc Version: 7.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sbergman at redhat dot com Target Milestone: --- At least with a recent GCC trunk build ("gcc (GCC) 7.0.1 20170221 (experimental)"), the below program does not print "dtor" when built with -std=c++17 (but does when built with -std=c++14, or with an older GCC, gcc-c++-6.3.1-1.fc25.x86_64). Appears that in the U ctor, a temporary shared_ptr<S> is copy-created but not destroyed. #include <iostream> #include <memory> struct S { ~S() { std::cout << "dtor\n"; } }; struct T { std::shared_ptr<S> s_; T(std::shared_ptr<S> s): s_(s) {} }; struct U { T t_; U(std::shared_ptr<S> const & s): t_(s) {} }; int main() { auto s = std::make_shared<S>(); U u(s); }