diff options
author | Jakub Jelinek <jakub@redhat.com> | 2021-03-03 16:12:23 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2021-03-03 16:12:23 +0100 |
commit | 0b8fa12015f717ac7e4fe2ffbad96a0cb0df2584 (patch) | |
tree | c9d4a4b312bb5497372bf0d486327886359765ac | |
parent | fa6092d2cdc654d4b2e018929c0dbe13fbd4ea69 (diff) | |
download | gcc-0b8fa12015f717ac7e4fe2ffbad96a0cb0df2584.zip gcc-0b8fa12015f717ac7e4fe2ffbad96a0cb0df2584.tar.gz gcc-0b8fa12015f717ac7e4fe2ffbad96a0cb0df2584.tar.bz2 |
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.
-rw-r--r-- | gcc/cp/call.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/eval-order10.C | 27 |
2 files changed, 36 insertions, 0 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c index b00334d..123f06b 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6083,6 +6083,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 0000000..02719b7 --- /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 (); +} |