Elision is a combination of lifetimes and object identities.
Elization can occur between a temporary (anonymous object) and the named object that it uses (directly), and between a function-local variable that is not a function argument and the return value of the function.
Elision commutes, essentially. (If objects A and B are dumped together, and B and C are dumped together, then essentially A and C are deleted together).
To return the return value of a function with a variable outside the function, you must directly construct this return value from the return value. Although in some contexts a constructed variable can be named before it is created, its use (similar to the one above) is undefined behavior until the constructor appears.
This constructor of the external variable is sequenced after the func body, and therefore after the func call. Thus, this could not have happened before calling func .
Here is an example of a case when we named a variable before it was created and passed it to func , then we initialized the variable with the func return value. It seems that the compiler decided not to step back in this case, but, as noted in the comments below, id really did: my call to UB hid the elite. (the convolution was an attempt to prevent the compiler from precomputing the values โโof test.x and test.y).
Yakk
source share