From 03e88100e14719f4e05dd379e88ae4daf68fa625 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 1 Dec 2016 17:13:06 -0500 Subject: [PATCH] call.c (add_function_candidate): Exclude inherited copy/move ctors. * call.c (add_function_candidate): Exclude inherited copy/move ctors. From-SVN: r243138 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/call.c | 19 +++++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/inh-ctor15a.C | 14 -------------- gcc/testsuite/g++.dg/cpp1z/inh-ctor36.C | 18 ++++++++++++++++++ 4 files changed, 42 insertions(+), 14 deletions(-) delete mode 100644 gcc/testsuite/g++.dg/cpp0x/inh-ctor15a.C create mode 100644 gcc/testsuite/g++.dg/cpp1z/inh-ctor36.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1a9a1ed3c4f..b407d17f4ec 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-12-01 Jason Merrill + + * call.c (add_function_candidate): Exclude inherited copy/move + ctors. + 2016-11-29 David Malcolm PR c++/77922 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 97003e53427..561cc83cd3b 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -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 index a9abb8428a1..00000000000 --- a/gcc/testsuite/g++.dg/cpp0x/inh-ctor15a.C +++ /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 index 00000000000..768a966d9f8 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/inh-ctor36.C @@ -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 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 +} -- 2.30.2