Before my patch for PR c++/21802, the function build_x_modify_expr() did not call build_new_op() during template processing (and thus did not do operator lookup); instead, it just built and returned a raw MODOP_EXPR.
After my patch, the function build_x_modify_expr() now calls build_new_op() even when processing a template. And when building a MODOP_EXPR/MODIFY_EXPR, build_new_op() eventually calls cp_build_modify_expr(), but that function apparently is not prepared to handle a MODIFY_EXPR whose LHS is a MODOP_EXPR, ultimately because it calls lvalue_kind() (via lvalue_or_else()) which returns clk_none for a MODOP_EXPR. And a non-lvalue can't be the LHS to a MODIFY_EXPR. Again, we did not have this problem before the mentioned patch because build_x_modify_expr() originally did not call build_new_op() at all during template processing. This is now necessary to in order to do operator lookup at template definition time. To fix this, I think lvalue_kind() should handle a MODOP_EXPR the same as a MODIFY_EXPR, at least during template processing, so it should return clk_ordinary instead of clk_none. Though I'm not sure if the added assert is entirely correct or appropriate.. Bootstrap and regtest in progress on x86_64-pc-linux-gnu, OK to commit if testing is OK? I will also try to build and test boost with this change. gcc/cp/ChangeLog: PR c++/68978 * tree.c (lvalue_kind) [MODOP_EXPR]: New case. gcc/testsuite/ChangeLog: PR c++/68978 * g++.dg/template/pr68978.C: New test. --- gcc/cp/tree.c | 6 +++++ gcc/testsuite/g++.dg/template/pr68978.C | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/pr68978.C diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index ae176d0..250fe27 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -185,6 +185,12 @@ lvalue_kind (const_tree ref) op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 2)); break; + case MODOP_EXPR: + /* We expect to see unlowered MODOP_EXPRs only during + template processing. */ + gcc_assert (processing_template_decl); + return clk_ordinary; + case MODIFY_EXPR: case TYPEID_EXPR: return clk_ordinary; diff --git a/gcc/testsuite/g++.dg/template/pr68978.C b/gcc/testsuite/g++.dg/template/pr68978.C new file mode 100644 index 0000000..b5946fc --- /dev/null +++ b/gcc/testsuite/g++.dg/template/pr68978.C @@ -0,0 +1,44 @@ +// PR c++/68978 + +extern int x, y, z; + +template <typename T> int toi_1() { + int i = 0, c = 0, radix = 10, max = 0x7fffffff; + if (max < ((i *= radix) += c)) + return 0; + return i; +} + +template <typename T> int toi_2() { + int i = 0, c = 0, radix = 10, max = 0x7fffffff; + if (max < ((i = radix) = c)) + return 0; + return i; +} + +template <typename T> int toi_3() { + int i = 0, c = 0, radix = 10, max = 0x7fffffff; + if (max < ((i = radix) += c)) + return 0; + return i; +} + +template <typename T> int toi_4() { + int i = 0, c = 0, radix = 10, max = 0x7fffffff; + if (max < ((i += radix) = c)) + return 0; + return i; +} + +template <typename T> int toi_5() { + int i = 0, c = 0, radix = 10, max = 0x7fffffff; + if (max < (((i = radix) = (c += 5)) *= 30)) + return 0; + return i; +} + +int a = toi_1<int> (); +int b = toi_2<int> (); +int c = toi_3<int> (); +int d = toi_4<int> (); +int e = toi_5<int> (); -- 2.7.0.rc0.50.g1470d8f.dirty