From 26d6ae55d88dddc2f2f99d9ac7bf11935307b4ec Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 23 May 2016 20:50:10 +0000 Subject: [PATCH] re PR c++/70972 (Inheriting constructors taking parameters by value should move them, not copy) /cp 2016-05-23 Paolo Carlini PR c++/70972 * method.c (forward_parm): Use cp_build_reference_type. /testsuite 2016-05-23 Paolo Carlini PR c++/70972 * g++.dg/cpp0x/inh-ctor20.C: New. * g++.dg/cpp0x/inh-ctor21.C: Likewise. From-SVN: r236614 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/method.c | 2 ++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/cpp0x/inh-ctor20.C | 16 ++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/inh-ctor21.C | 19 +++++++++++++++++++ 5 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/inh-ctor20.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/inh-ctor21.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 764754d54d1..6201bdaa036 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-05-23 Paolo Carlini + + PR c++/70972 + * method.c (forward_parm): Use cp_build_reference_type. + 2016-05-23 Paolo Carlini PR c++/69095 diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 310e7ebe728..cd8faaf483f 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -484,6 +484,8 @@ forward_parm (tree parm) tree type = TREE_TYPE (parm); if (DECL_PACK_P (parm)) type = PACK_EXPANSION_PATTERN (type); + if (TREE_CODE (type) != REFERENCE_TYPE) + type = cp_build_reference_type (type, /*rval=*/true); exp = build_static_cast (type, exp, tf_warning_or_error); if (DECL_PACK_P (parm)) exp = make_pack_expansion (exp); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 80b62ad5225..ef528f20344 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-05-23 Paolo Carlini + + PR c++/70972 + * g++.dg/cpp0x/inh-ctor20.C: New. + * g++.dg/cpp0x/inh-ctor21.C: Likewise. + 2016-05-23 Paolo Carlini PR c++/69095 diff --git a/gcc/testsuite/g++.dg/cpp0x/inh-ctor20.C b/gcc/testsuite/g++.dg/cpp0x/inh-ctor20.C new file mode 100644 index 00000000000..f33056df493 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/inh-ctor20.C @@ -0,0 +1,16 @@ +// PR c++/70972 +// { dg-do compile { target c++11 } } + +struct moveonly { + moveonly(moveonly&&) = default; + moveonly() = default; +}; + +struct A { + A(moveonly) {} +}; +struct B : A { + using A::A; +}; + +B b(moveonly{}); diff --git a/gcc/testsuite/g++.dg/cpp0x/inh-ctor21.C b/gcc/testsuite/g++.dg/cpp0x/inh-ctor21.C new file mode 100644 index 00000000000..64655068a0a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/inh-ctor21.C @@ -0,0 +1,19 @@ +// PR c++/70972 +// { dg-do run { target c++11 } } + +struct abort_on_copy{ + abort_on_copy(abort_on_copy&&) = default; + abort_on_copy(const abort_on_copy&) { __builtin_abort(); } + abort_on_copy() = default; +}; + +struct A { + A(abort_on_copy) {} +}; +struct B : A { + using A::A; +}; + +int main() { + B b(abort_on_copy{}); +} -- 2.30.2