Re: C++ PATCH to stop inheriting copy constructors

2016-12-02 Thread Ville Voutilainen
On 2 December 2016 at 16:00, Jason Merrill  wrote:
> In C++14 copy constructors were excluded from the inherited
> constructor set; Ville noticed that this was changed in the new
> inherited constructor rules, and lobbied for us to retain the old
> behavior in that case.  This patch implements the proposed resolution.


s/lobbied/convinced with reasonable rationale/ :) Smashing, thanks for
the quick fix.


C++ PATCH to stop inheriting copy constructors

2016-12-02 Thread Jason Merrill
In C++14 copy constructors were excluded from the inherited
constructor set; Ville noticed that this was changed in the new
inherited constructor rules, and lobbied for us to retain the old
behavior in that case.  This patch implements the proposed resolution.

Tested x86_64-pc-linux-gnu, applied to trunk.
2016-12-01  Jason Merrill  

* call.c (add_function_candidate): Exclude inherited copy/move
ctors.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 97003e5..b7aa97c 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -2042,6 +2042,24 @@ add_function_candidate (struct z_candidate **candidates,
   reason = arity_rejection (first_arg, i + remaining, len);
 }
 
+  /* An inherited constructor (12.6.3 [class.inhctor.init]) that 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 D with an argument list
+ containing a single argument if C is reference-related to D.  */
+  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 dtype = DECL_CONTEXT (fn);
+  if (reference_related_p (ptype, dtype))
+   {
+ viable = false;
+ reason = inherited_ctor_rejection ();
+   }
+}
+
   /* Second, for a function to be viable, its constraints must be
  satisfied. */
   if (flag_concepts && viable
@@ -2142,18 +2160,6 @@ add_function_candidate (struct z_candidate **candidates,
}
}
 
- /* Don't consider inherited constructors for initialization from an
-expression of the same or derived type.  */
- /* FIXME extend to operator=.  */
- if (i == 0 && len == 1
- && DECL_INHERITED_CTOR (fn)
- && reference_related_p (ctype, argtype))
-   {
- viable = 0;
- reason = inherited_ctor_rejection ();
- goto out;
-   }
-
  /* Core issue 899: When [copy-]initializing a temporary to be bound
 to the first parameter of a copy constructor (12.8) called with
 a single argument in the context of direct-initialization,