From e5ba9b702f14441f43a577e9f44192c14a43cd7b Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Sat, 8 Sep 2018 17:36:08 +0000 Subject: [PATCH] PR c++/87150 - wrong ctor with maybe-rvalue semantics. * call.c (struct conversion): Update commentary. (standard_conversion): Set rvaluedness_matches_p if LOOKUP_PREFER_RVALUE for ck_base. * g++.dg/cpp0x/move-return2.C: New test. From-SVN: r264172 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/call.c | 9 ++++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/move-return2.C | 11 +++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/move-return2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c0fa4660df9..76fe61eff64 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-09-08 Marek Polacek + + PR c++/87150 - wrong ctor with maybe-rvalue semantics. + * call.c (struct conversion): Update commentary. + (standard_conversion): Set rvaluedness_matches_p if LOOKUP_PREFER_RVALUE + for ck_base. + 2018-09-08 Jason Merrill PR c++/86678 - constexpr function with non-constant after return. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 942b2c204be..03b4c5ab224 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -102,10 +102,10 @@ struct conversion { BOOL_BITFIELD base_p : 1; /* If KIND is ck_ref_bind, true when either an lvalue reference is being bound to an lvalue expression or an rvalue reference is - being bound to an rvalue expression. If KIND is ck_rvalue, + being bound to an rvalue expression. If KIND is ck_rvalue or ck_base, true when we are treating an lvalue as an rvalue (12.8p33). If - KIND is ck_base, always false. If ck_identity, we will be - binding a reference directly or decaying to a pointer. */ + ck_identity, we will be binding a reference directly or decaying to + a pointer. */ BOOL_BITFIELD rvaluedness_matches_p: 1; BOOL_BITFIELD check_narrowing: 1; /* Whether check_narrowing should only check TREE_CONSTANTs; used @@ -1425,6 +1425,9 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p, type. A temporary object is created to hold the result of the conversion unless we're binding directly to a reference. */ conv->need_temporary_p = !(flags & LOOKUP_NO_TEMP_BIND); + if (flags & LOOKUP_PREFER_RVALUE) + /* Tell convert_like_real to set LOOKUP_PREFER_RVALUE. */ + conv->rvaluedness_matches_p = true; } else return NULL; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 15e3979fae1..0c038441a8c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-09-08 Marek Polacek + + PR c++/87150 - wrong ctor with maybe-rvalue semantics. + * g++.dg/cpp0x/move-return2.C: New test. + 2018-09-08 Marek Polacek * c-c++-common/array-init.c: Add dg-prune-output. diff --git a/gcc/testsuite/g++.dg/cpp0x/move-return2.C b/gcc/testsuite/g++.dg/cpp0x/move-return2.C new file mode 100644 index 00000000000..681e9ecaca1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/move-return2.C @@ -0,0 +1,11 @@ +// PR c++/87150 +// { dg-do compile { target c++11 } } + +struct S1 { S1(S1 &&); }; +struct S2 : S1 {}; + +S1 +f (S2 s) +{ + return s; // { dg-error "use of deleted function" } +} -- 2.30.2