]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
call.c (add_function_candidate): Exclude inherited copy/move ctors.
authorJason Merrill <jason@redhat.com>
Thu, 1 Dec 2016 22:13:06 +0000 (17:13 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 1 Dec 2016 22:13:06 +0000 (17:13 -0500)
* call.c (add_function_candidate): Exclude inherited copy/move
ctors.

From-SVN: r243138

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/g++.dg/cpp0x/inh-ctor15a.C [deleted file]
gcc/testsuite/g++.dg/cpp1z/inh-ctor36.C [new file with mode: 0644]

index 1a9a1ed3c4fbc12118e937f86f5f87b078b21144..b407d17f4ec8b9eccbd927a244ddb2a6cbc221b0 100644 (file)
@@ -1,3 +1,8 @@
+2016-12-01  Jason Merrill  <jason@redhat.com>
+
+       * call.c (add_function_candidate): Exclude inherited copy/move
+       ctors.
+
 2016-11-29  David Malcolm  <dmalcolm@redhat.com>
 
        PR c++/77922
index 97003e534270b5f70b768e7b6a8930fffd1b9a15..561cc83cd3b306b54861f87856f68b111ab1b1f9 100644 (file)
@@ -2042,6 +2042,25 @@ add_function_candidate (struct z_candidate **candidates,
       reason = arity_rejection (first_arg, i + remaining, len);
     }
 
+  /* A constructor that is a direct member of a class C and has a first
+     parameter of type "reference to cv C" (including such a constructor
+     instantiated from a template) is excluded from the set of candidate
+     functions when used to construct an object of type derived from C (12.6.3
+     [class.inhctor.init]) with an argument list containing a single
+     argument.  */
+  if (viable && len == 1 && parmlist && DECL_CONSTRUCTOR_P (fn)
+      && flag_new_inheriting_ctors
+      && DECL_INHERITED_CTOR (fn))
+    {
+      tree ptype = non_reference (TREE_VALUE (parmlist));
+      tree ctype = DECL_INHERITED_CTOR_BASE (fn);
+      if (same_type_ignoring_top_level_qualifiers_p (ptype, ctype))
+       {
+         viable = false;
+         reason = inherited_ctor_rejection ();
+       }
+    }
+
   /* Second, for a function to be viable, its constraints must be
      satisfied. */
   if (flag_concepts && viable
diff --git a/gcc/testsuite/g++.dg/cpp0x/inh-ctor15a.C b/gcc/testsuite/g++.dg/cpp0x/inh-ctor15a.C
deleted file mode 100644 (file)
index a9abb84..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-// P0136 caused us to start inheriting base copy constructors.
-// { dg-do compile { target c++11 } }
-// { dg-options -fnew-inheriting-ctors }
-
-struct A { A(int); };
-struct B: public A
-{
-  using A::A;
-};
-
-A a (42);
-
-B b1 (24);                     // inherited
-B b2 (a);                      // also inherited now
diff --git a/gcc/testsuite/g++.dg/cpp1z/inh-ctor36.C b/gcc/testsuite/g++.dg/cpp1z/inh-ctor36.C
new file mode 100644 (file)
index 0000000..768a966
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-do link { target c++11 } }
+
+struct X { X(X &&); };
+struct A {
+  A() {}
+  A(const A&);       // #1
+  A(A &&) = default; // #2, defined as deleted (12.8 [class.copy])
+  template<typename T> A(T &&);        // #3
+  union { X x; };
+};
+struct B : A {
+  using A::A;
+  B(...) {}
+};
+
+int main() {
+  B b = A(); // calls B::B(...): #1, #2, and #3 are excluded from candidate set
+}