[webkit-dev] PSA: Don't try to hold onto temporaries with references

Adam Barth abarth at webkit.org
Sun Oct 3 02:21:34 PDT 2010

If a function returns a temporary, you probably don't want to hold
onto it with a "const Foo& foo".  The temporary will get deallocated
and then you'll be left with a reference to dead memory, which is bad
new bears:


This kind of thing can be tricky to spot in code reviews because it's
not obvious at the call site whether a function turns a temporary or a
reference to some existing object.


More information about the webkit-dev mailing list