Patchwork C++ PATCH for c++/56285 (wrong error with inheriting ctor)

login
register
mail settings
Submitter Jason Merrill
Date Feb. 12, 2013, 8:46 p.m.
Message ID <511AAA40.5010103@redhat.com>
Download mbox | patch
Permalink /patch/219948/
State New
Headers show

Comments

Jason Merrill - Feb. 12, 2013, 8:46 p.m.
We need to move for rvalue ref parms as well as value ones.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit 29189e48dc7a62ff6a3a67984dbc64f4ada72862
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Feb 12 12:56:52 2013 -0500

    	PR c++/56285
    	* method.c (add_one_base_init): Handle base constructor
    	taking rvalue reference parm.

diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index a1bab95..ff29b59 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -500,7 +500,8 @@  add_one_base_init (tree binfo, tree parm, bool move_p, tree inh,
       for (; parm; parm = DECL_CHAIN (parm))
 	{
 	  tree exp = convert_from_reference (parm);
-	  if (TREE_CODE (TREE_TYPE (parm)) != REFERENCE_TYPE)
+	  if (TREE_CODE (TREE_TYPE (parm)) != REFERENCE_TYPE
+	      || TYPE_REF_IS_RVALUE (TREE_TYPE (parm)))
 	    exp = move (exp);
 	  *p = build_tree_list (NULL_TREE, exp);
 	  p = &TREE_CHAIN (*p);
diff --git a/gcc/testsuite/g++.dg/cpp0x/inh-ctor16.C b/gcc/testsuite/g++.dg/cpp0x/inh-ctor16.C
new file mode 100644
index 0000000..58e848b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/inh-ctor16.C
@@ -0,0 +1,15 @@ 
+// PR c++/56285
+// { dg-options -std=c++11 }
+
+struct foo {
+    explicit foo(int&&) {}
+};
+
+struct bar: private foo {
+    using foo::foo;
+};
+
+int main()
+{
+    bar b { 42 };
+}