public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-9429] c++: Fix -fstrong-eval-order for operator &&, || and , [PR82959] Date: Tue, 20 Apr 2021 23:33:13 +0000 (GMT) [thread overview] Message-ID: <20210420233313.A7A403AA9905@sourceware.org> (raw) https://gcc.gnu.org/g:6c085d6d783f38f008ea54f80b43f6b8e8f6b971 commit r9-9429-g6c085d6d783f38f008ea54f80b43f6b8e8f6b971 Author: Jakub Jelinek <jakub@redhat.com> Date: Wed Mar 3 16:12:23 2021 +0100 c++: Fix -fstrong-eval-order for operator &&, || and , [PR82959] P0145R3 added "However, the operands are sequenced in the order prescribed for the built-in operator" rule for overloaded operator calls when using the operator syntax. op_is_ordered follows that, but added just the overloaded operators added in that paper. &&, || and comma operators had rules that lhs is sequenced before rhs already in C++98. The following patch adds those cases to op_is_ordered. 2021-03-03 Jakub Jelinek <jakub@redhat.com> PR c++/82959 * call.c (op_is_ordered): Handle TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR and COMPOUND_EXPR. * g++.dg/cpp1z/eval-order10.C: New test. (cherry picked from commit 529e3b3402bd2a97b02318bd834df72815be5f0f) Diff: --- gcc/cp/call.c | 9 +++++++++ gcc/testsuite/g++.dg/cpp1z/eval-order10.C | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 7191a4945b1..5822a85f520 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -5790,6 +5790,15 @@ op_is_ordered (tree_code code) case LSHIFT_EXPR: // 8. a >> b case RSHIFT_EXPR: + // a && b + // Predates P0145R3. + case TRUTH_ANDIF_EXPR: + // a || b + // Predates P0145R3. + case TRUTH_ORIF_EXPR: + // a , b + // Predates P0145R3. + case COMPOUND_EXPR: return (flag_strong_eval_order ? 1 : 0); default: diff --git a/gcc/testsuite/g++.dg/cpp1z/eval-order10.C b/gcc/testsuite/g++.dg/cpp1z/eval-order10.C new file mode 100644 index 00000000000..02719b7e810 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/eval-order10.C @@ -0,0 +1,27 @@ +// PR c++/82959 +// { dg-do run } +// { dg-additional-options -fstrong-eval-order } + +struct A {}; + +void operator && (const A x, const A) {} +void operator || (const A x, const A) {} +void operator , (const A x, const A) {} + +int i; + +A f () { if (i != 0) __builtin_abort (); i = 1; return A (); } +A g () { if (i != 1) __builtin_abort (); i = 2; return A (); } + +int +main () +{ + f () && g (); + if (i != 2) __builtin_abort (); + i = 0; + f () || g (); + if (i != 2) __builtin_abort (); + i = 0; + f (), g (); + if (i != 2) __builtin_abort (); +}
reply other threads:[~2021-04-20 23:33 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=20210420233313.A7A403AA9905@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@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: linkBe 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).