https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119466
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=97288
Last reconfirmed| |2025-03-25
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:
extern "C" int printf(const char*, ...);
int func(int &x, int *&y) {
y = &x;
x++;
return x;
}
int main() {
int a = 4;
int b = 9;
int *c = &b;
*c = func(a, c);
printf("%d%d%d\n", a, *c, b);
}
It seems that GCC evaluates the left operand *c before the right operand
func(a, c), so the assignment is done to the wrong location.
Before C++17 that was OK, but C++17 fixed the order of evaluation for
assignment expressions.
EDG gives the same result as GCC.
I think this is a duplicate of Bug 97288