https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109945

--- Comment #28 from Jonathan Wakely <redi at gcc dot gnu.org> ---
What I tried to say in comment 26 is that we're allowed to always make the
extra copy, which means that global is an invalid pointer, so the program has
UB.

I think the only flaw in that reasoning is what Richard Smith said in PR 84414
comment 2:

"In fact, I think the *only* problem here is that the above rule does not allow
the caller and the callee to observe the objects having the same address."

I would argue that it doesn't say they *can't* have the same address (even if
logically it seems obvious that if we copy a temporary to w then at some point
there must have been two distinct objects with two distinct addresses).

But since one of the pointers is an invalid pointer, you can't do anything with
its value anyway, including comparing it to &w. We can pretend that `global`
initially has the address of the temporary, but after that temporary goes out
of scope and `global` becomes an invalid pointer it bit-flips to some other
address, which happens to be the same bit-pattern as &w. But you can't observe
that in a correct program.

Reply via email to