Problem with evaluation order in assignment expression after c++17

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux