This question is in different aspect (also limited to gcc). My question is meant only for unnamed objects. Return Value Optimization is allowed to chang
Pedantically speaking its implementation defined. Modern compilers are intelligent enough to do such kind of optimization.
But there is no guarantee that the behavior would be exactly same across implementations. That's what implementation defined behavior is all about.
"allowed to" in this context means that 0 or 1 or 2 are standard conforming outputs.