* [PATCH] c++: Fix -fstrong-eval-order for operator &&, || and , [PR82959]
@ 2021-03-02 23:10 Jakub Jelinek
2021-03-03 15:06 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2021-03-02 23:10 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
Hi!
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.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2021-03-02 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.
--- gcc/cp/call.c.jj 2021-02-19 12:14:10.965113839 +0100
+++ gcc/cp/call.c 2021-03-02 13:32:08.423924095 +0100
@@ -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:
--- gcc/testsuite/g++.dg/cpp1z/eval-order10.C.jj 2021-03-02 14:15:21.735278240 +0100
+++ gcc/testsuite/g++.dg/cpp1z/eval-order10.C 2021-03-02 14:24:36.984143267 +0100
@@ -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 ();
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: Fix -fstrong-eval-order for operator &&, || and , [PR82959]
2021-03-02 23:10 [PATCH] c++: Fix -fstrong-eval-order for operator &&, || and , [PR82959] Jakub Jelinek
@ 2021-03-03 15:06 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2021-03-03 15:06 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On 3/2/21 6:10 PM, Jakub Jelinek wrote:
> Hi!
>
> 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.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
> 2021-03-02 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.
>
> --- gcc/cp/call.c.jj 2021-02-19 12:14:10.965113839 +0100
> +++ gcc/cp/call.c 2021-03-02 13:32:08.423924095 +0100
> @@ -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:
> --- gcc/testsuite/g++.dg/cpp1z/eval-order10.C.jj 2021-03-02 14:15:21.735278240 +0100
> +++ gcc/testsuite/g++.dg/cpp1z/eval-order10.C 2021-03-02 14:24:36.984143267 +0100
> @@ -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 ();
> +}
>
> Jakub
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-03 15:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-02 23:10 [PATCH] c++: Fix -fstrong-eval-order for operator &&, || and , [PR82959] Jakub Jelinek
2021-03-03 15:06 ` Jason Merrill
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).