Closed davidmlw closed 6 years ago
int main() { shared_ptr
foo; { auto ip = make_shared (41);
ip
is local to this scope.
auto a = foo_expr(ip);
a
is local to this scope, and contains a lvalue reference to ip
, which is also local.
foo = build_foo(a + 1);
foo
now contains an lvalue reference to a
, and transitively to ip
.
}
Now all references to ip
and a
are dangling.
{ run(foo); // wrong ip has been released }
The handling of expressions in YAP, is covered in the "How Expression Operands Are Treated" section of the docs:
I designed a class that uses shared_ptr to contain resources. But when I use Expr::term to hold the objects of that class, the resources will be released since they are "moved" out. Here is a piece of code to demonstrate my purpose. Would you please help me out?
Best regards,