4 ms·
Yes, the same thought occurred to me (that perhaps clang is careful in the caller in the case the address escapes), but I seemed to find cases where clang optim
by BeeOnRope 8y ago
Yes, the same thought occurred to me (that perhaps clang is careful in the caller in the case the address escapes), but I seemed to find cases where clang optimizes the caller also, so that two distinct objects receive the same pointer and both pointers escape.
Here's an example:
https://godbolt.org/g/yxFzqT https://godbolt.org/g/yxFzqT
This happens on clang versions back 3.6.
Note that if you change the caller to:
Foo f;
f = callee(&f);
the code changes and distinct objects are passed. I'm not sure if the first form (all in the definition) has a relevant difference per the standard that lets clang do this.