aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2016-12-01 17:13:06 -0500
committerJason Merrill <jason@gcc.gnu.org>2016-12-01 17:13:06 -0500
commit03e88100e14719f4e05dd379e88ae4daf68fa625 (patch)
treed14cda22c0c29f2f811e5d9221fd6ca057f5be61
parentc1ff51dc9f743fb6ecd77a9374e543d285f98cb0 (diff)
downloadgcc-03e88100e14719f4e05dd379e88ae4daf68fa625.zip
gcc-03e88100e14719f4e05dd379e88ae4daf68fa625.tar.gz
gcc-03e88100e14719f4e05dd379e88ae4daf68fa625.tar.bz2
call.c (add_function_candidate): Exclude inherited copy/move ctors.
* call.c (add_function_candidate): Exclude inherited copy/move ctors. From-SVN: r243138
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/call.c19
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/inh-ctor15a.C14
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/inh-ctor36.C18
4 files changed, 42 insertions, 14 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1a9a1ed..b407d17 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 97003e5..561cc83 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 a9abb84..0000000
--- 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 0000000..768a966
--- /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<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
+}