* Problem with evaluation order in assignment expression after c++17
@ 2022-08-23 14:37 cyb_yorkin
0 siblings, 0 replies; only message in thread
From: cyb_yorkin @ 2022-08-23 14:37 UTC (permalink / raw)
To: gcc-help
Hi all,
After c++17, the standard in section [expr.ass] guarantees "right operand is sequenced before the left operand".
I wrote this code, tested in gcc 12.1.
```
#include<iostream>
using namespace std;
int a = 1, b = 1;
int *ptr = &a;
int f(){
ptr = &b;
return 9;
}
int main(){
*ptr = f();
cout<<a<<','<<b<<endl;
}
```
I assume the program will evaluate function f first (it changed the ptr), and then get address of b from the pointer. After that, store returned value into b.
The output should be "1,9", like clang. but gcc give me "9,1".
You can check this here: https://godbolt.org/z/9P3cj7nYs
I wonder is that a gcc's bug or am I miss something else in c++ standard.
Thanks.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-08-23 14:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-23 14:37 Problem with evaluation order in assignment expression after c++17 cyb_yorkin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).