The compiler is allowed to evaluate this expression in the following order:
auto __temp1 = new int(42); auto __temp2 = g(); auto __temp3 = shared_ptr<int>(__temp1); f(__temp3, __temp2);
You can see that if g() throws, then the selected object is never deleted.
Using make_shared , nothing can happen between the distribution of an object and the initialization of a smart pointer to manage it.
source share