2012-11-19 Jason Merrill <jason@redhat.com>
+ * class.c (one_inheriting_sig): Don't inherit base copy ctors.
+
PR c++/55262
* method.c (implicitly_declare_fn): Set DECL_PARM_INDEX on
the parms of an inheriting ctor.
one_inheriting_sig (tree t, tree ctor, tree *parms, int nparms)
{
/* We don't declare an inheriting ctor that would be a default,
- copy or move ctor. */
- if (nparms == 0
- || (nparms == 1
- && TREE_CODE (parms[0]) == REFERENCE_TYPE
- && TYPE_MAIN_VARIANT (TREE_TYPE (parms[0])) == t))
+ copy or move ctor for derived or base. */
+ if (nparms == 0)
return;
- int i;
+ if (nparms == 1
+ && TREE_CODE (parms[0]) == REFERENCE_TYPE)
+ {
+ tree parm = TYPE_MAIN_VARIANT (TREE_TYPE (parms[0]));
+ if (parm == t || parm == DECL_CONTEXT (ctor))
+ return;
+ }
+
tree parmlist = void_list_node;
- for (i = nparms - 1; i >= 0; i--)
+ for (int i = nparms - 1; i >= 0; i--)
parmlist = tree_cons (NULL_TREE, parms[i], parmlist);
tree fn = implicitly_declare_fn (sfk_inheriting_constructor,
t, false, ctor, parmlist);
--- /dev/null
+// Discussions on the core reflector indicate that not inheriting base copy
+// constructors was a deliberate choice.
+
+// { dg-options -std=c++11 }
+
+struct A { A(int); };
+struct B: public A
+{
+ using A::A;
+};
+
+A a (42);
+
+B b1 (24); // inherited
+B b2 (a); // not inherited { dg-error "no match" }