re PR c++/70972 (Inheriting constructors taking parameters by value should move them...
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 23 May 2016 20:50:10 +0000 (20:50 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 23 May 2016 20:50:10 +0000 (20:50 +0000)
/cp
2016-05-23  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/70972
* method.c (forward_parm): Use cp_build_reference_type.

/testsuite
2016-05-23  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/70972
* g++.dg/cpp0x/inh-ctor20.C: New.
* g++.dg/cpp0x/inh-ctor21.C: Likewise.

From-SVN: r236614

gcc/cp/ChangeLog
gcc/cp/method.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/inh-ctor20.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/inh-ctor21.C [new file with mode: 0644]

index 764754d54d126203fee059ff0221800e3de19330..6201bdaa036f36ce3ca1eba3c8825ccba9d3d83d 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-23  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/70972
+       * method.c (forward_parm): Use cp_build_reference_type.
+
 2016-05-23  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/69095
index 310e7ebe728a677f98a10b67ee74cf7c40bfcec0..cd8faaf483f67cabc724820042a2e1058ed11f63 100644 (file)
@@ -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);
index 80b62ad5225e0ec0ab4b84282f2a71cc947e75a5..ef528f203447deedd385718d6846cb4374df45d7 100644 (file)
@@ -1,3 +1,9 @@
+2016-05-23  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/70972
+       * g++.dg/cpp0x/inh-ctor20.C: New.
+       * g++.dg/cpp0x/inh-ctor21.C: Likewise.
+
 2016-05-23  Paolo Carlini  <paolo.carlini@oracle.com>
 
        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 (file)
index 0000000..f33056d
--- /dev/null
@@ -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 (file)
index 0000000..6465506
--- /dev/null
@@ -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{});
+}