c++: Fix C++17 eval order for virtual op=.
authorJason Merrill <jason@redhat.com>
Fri, 22 May 2020 21:06:57 +0000 (17:06 -0400)
committerJason Merrill <jason@redhat.com>
Sat, 23 May 2020 00:50:31 +0000 (20:50 -0400)
commitb2b8eb6202b83218cf135eebbf992a833057f6bf
tree3e09437f142519248dbb6f0d7bd4039c3b6284bc
parentfabd4f16a15690d38b335c0471d1b1ca94ed1b34
c++: Fix C++17 eval order for virtual op=.

In a function call expression in C++17 evaluation of the function pointer is
sequenced before evaluation of the function arguments, but that doesn't
apply to function calls that were written using operator syntax.  In
particular, for operators with right-to-left ordering like assignment, we
must not evaluate the LHS to find a virtual function before we evaluate the
RHS.

gcc/cp/ChangeLog:

* cp-gimplify.c (cp_gimplify_expr) [CALL_EXPR]: Don't preevaluate
the function address if the call used operator syntax.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/eval-order9.C: New test.
gcc/cp/cp-gimplify.c
gcc/testsuite/g++.dg/cpp1z/eval-order9.C [new file with mode: 0644]