The problem here was that we were calling save_expr in a template, which we shouldn't, as the comment in cp_save_expr explains. This problem only appears on ptrmemfunc_vbit_in_delta targets.
Bootstrapped/regtested on aarch64-linux, ok for trunk? 2018-11-26 Marek Polacek <pola...@redhat.com> PR c++/88120 - ICE when calling save_expr in a template. * typeck.c (cp_build_binary_op): Call cp_save_expr instead of save_expr. * g++.dg/cpp0x/pr88120.C: New test. diff --git gcc/cp/typeck.c gcc/cp/typeck.c index 81cb4057a5b..f45c06e3fe4 100644 --- gcc/cp/typeck.c +++ gcc/cp/typeck.c @@ -4919,7 +4919,7 @@ cp_build_binary_op (location_t location, tree pfn0, delta0, e1, e2; if (TREE_SIDE_EFFECTS (op0)) - op0 = save_expr (op0); + op0 = cp_save_expr (op0); pfn0 = pfn_from_ptrmemfunc (op0); delta0 = delta_from_ptrmemfunc (op0); diff --git gcc/testsuite/g++.dg/cpp0x/pr88120.C gcc/testsuite/g++.dg/cpp0x/pr88120.C new file mode 100644 index 00000000000..7004e03f4da --- /dev/null +++ gcc/testsuite/g++.dg/cpp0x/pr88120.C @@ -0,0 +1,23 @@ +// PR c++/88120 +// { dg-do compile { target c++11 } } + +typedef int a; +enum b : a; +class c { + enum f { d }; + c(f); + friend c operator&(c, c); + typedef void (c::*e)(); + operator e(); +}; +class g { + template <typename, typename> b h(); + struct k { + c i; + }; +}; +template <typename, typename> b g::h() { + k j; + &j || j.i &c::d; + return b(); +}