I know how does the postincrement in C++ work. Also, the C++ standard says that the behaviour of things like y = x++ + x is undefined, as there is no guarantee for the order in which are the operands of + evaluated. However, I've heard that g++ (possibly clang too) compiles such code in a way that x is incremented really after the WHOLE expression is evaluated.
So my questions are - how does that happen? And, more importantly, how can I imitate the same behaviour with my own class and an overloaded operator? I take into account that the behaviour of my class would probably be g++-specific, undefined by the C++ standard, and generaly not a wise thing to do, but I'm asking out of curiosity.