diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index 340b4641046..83ba1285bfd 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -250,7 +250,10 @@ cp_gimplify_init_expr (tree *expr_p) if (TREE_CODE (from) == TARGET_EXPR) if (tree init = TARGET_EXPR_INITIAL (from)) { - gcc_checking_assert (TARGET_EXPR_ELIDING_P (from)); + /* Make sure that we expected to elide this temporary. But also allow + gimplify_modify_expr_rhs to elide temporaries of trivial type. */ + gcc_checking_assert (TARGET_EXPR_ELIDING_P (from) + || !TREE_ADDRESSABLE (TREE_TYPE (from))); if (target_expr_needs_replace (from)) { /* If this was changed by cp_genericize_target_expr, we need to diff --git a/gcc/testsuite/g++.dg/cpp0x/move2.C b/gcc/testsuite/g++.dg/cpp0x/move2.C new file mode 100644 index 00000000000..b8c8683c4d2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/move2.C @@ -0,0 +1,14 @@ +// PR c++/107267 +// { dg-do compile { target c++11 } } +// { dg-additional-options -ffold-simple-inlines } + +namespace std { + template _Tp &&move(_Tp &&); +} + +struct FindResult { + FindResult(); + int result; +}; + +FindResult pop_ret = std::move(FindResult());