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

--- Comment #7 from Kio <bugzi...@little-bat.de> ---
(In reply to Andreas Schwab from comment #5)
> The operator++ function is expected to modify the argument in place, and
> needs to take a reference to it.

Yes, that's my error! after modifying the operators to:

Foo operator++(Foo& n,int) { Foo v=n; n=Foo(int(n)+1); return v; }
Foo& operator++(Foo& n)    { return n=Foo(int(n)+1); }

then the compiled code is as expected.

Obviously arg#1 must be a reference, because the argument must be modified.
Actually i think this code should not compile or at least produce a warning (i
compile with almost all warnings on, but that went silent). When passing a
value the operator can't do what is expected.

Reply via email to