From: "cyb_yorkin@outlook.com" <cyb_yorkin@outlook.com>
To: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: Problem with evaluation order in assignment expression after c++17
Date: Tue, 23 Aug 2022 14:37:48 +0000 [thread overview]
Message-ID: <TYCPR01MB9385BEFA862AC062F50D3CECF3709@TYCPR01MB9385.jpnprd01.prod.outlook.com> (raw)
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.
reply other threads:[~2022-08-23 14:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=TYCPR01MB9385BEFA862AC062F50D3CECF3709@TYCPR01MB9385.jpnprd01.prod.outlook.com \
--to=cyb_yorkin@outlook.com \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).