diff mbox

[C++] move ctors and assign (again)

Message ID 31bb6f5c-6e88-8c31-0d15-7db4df7fb6b0@acm.org
State New
Headers show

Commit Message

Nathan Sidwell July 18, 2017, 12:07 p.m. UTC
In addition to the user-declared checkers, we also have a couple of 'do 
we have at all' predicates.  Used exactly once when completing a struct 
and determining the state of the appropriate LAZY flags.

Merged with the attached patch committed to trunk.  Now the two 
functions are stunningly similar a further merging may be in the near 
future ...

nathan
diff mbox

Patch

2017-07-18  Nathan Sidwell  <nathan@acm.org>

	* class.c (classtype_has_move_assign_or_move_ctor): Declare.
	(add_implicitly_declared_members): Use it.
	(type_has_move_constructor, type_has_move_assign): Merge into ...
	(classtype_has_move_assign_or_move_ctor): ... this new function.
	* cp-tree.h (type_has_move_constructor, type_has_move_assign): Delete.

Index: class.c
===================================================================
--- class.c	(revision 250281)
+++ class.c	(working copy)
@@ -150,6 +150,7 @@  static void build_base_fields (record_la
 static void check_methods (tree);
 static void remove_zero_width_bit_fields (tree);
 static bool accessible_nvdtor_p (tree);
+static bool classtype_has_move_assign_or_move_ctor (tree);
 
 /* Used by find_flexarrays and related functions.  */
 struct flexmems_t;
@@ -3384,7 +3385,7 @@  add_implicitly_declared_members (tree t,
   bool move_ok = false;
   if (cxx_dialect >= cxx11 && CLASSTYPE_LAZY_DESTRUCTOR (t)
       && !TYPE_HAS_COPY_CTOR (t) && !TYPE_HAS_COPY_ASSIGN (t)
-      && !type_has_move_constructor (t) && !type_has_move_assign (t))
+      && !classtype_has_move_assign_or_move_ctor (t))
     move_ok = true;
 
   /* [class.ctor]
@@ -5456,38 +5457,19 @@  type_has_virtual_destructor (tree type)
   return (dtor && DECL_VIRTUAL_P (dtor));
 }
 
-/* Returns true iff class T has a move constructor.  */
+/* Returns true iff class T has move assignment or move constructor.  */
 
-bool
-type_has_move_constructor (tree t)
+static bool
+classtype_has_move_assign_or_move_ctor (tree t)
 {
-  if (CLASSTYPE_LAZY_MOVE_CTOR (t))
-    {
-      gcc_assert (COMPLETE_TYPE_P (t));
-      lazily_declare_fn (sfk_move_constructor, t);
-    }
+  gcc_assert (!CLASSTYPE_LAZY_MOVE_CTOR (t)
+	      && !CLASSTYPE_LAZY_MOVE_ASSIGN (t));
 
-  if (!CLASSTYPE_METHOD_VEC (t))
-    return false;
-
-  for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
+  for (ovl_iterator iter (lookup_fnfields_slot_nolazy
+			  (t, ctor_identifier)); iter; ++iter)
     if (move_fn_p (*iter))
       return true;
 
-  return false;
-}
-
-/* Returns true iff class T has a move assignment operator.  */
-
-bool
-type_has_move_assign (tree t)
-{
-  if (CLASSTYPE_LAZY_MOVE_ASSIGN (t))
-    {
-      gcc_assert (COMPLETE_TYPE_P (t));
-      lazily_declare_fn (sfk_move_assignment, t);
-    }
-
   for (ovl_iterator iter (lookup_fnfields_slot_nolazy
 			  (t, cp_assignment_operator_id (NOP_EXPR)));
        iter; ++iter)
Index: cp-tree.h
===================================================================
--- cp-tree.h	(revision 250280)
+++ cp-tree.h	(working copy)
@@ -6023,8 +6023,6 @@  extern tree default_init_uninitialized_p
 extern bool trivial_default_constructor_is_constexpr (tree);
 extern bool type_has_constexpr_default_constructor (tree);
 extern bool type_has_virtual_destructor		(tree);
-extern bool type_has_move_constructor		(tree);
-extern bool type_has_move_assign		(tree);
 extern bool classtype_has_user_move_assign_or_move_ctor_p (tree);
 extern bool type_build_ctor_call		(tree);
 extern bool type_build_dtor_call		(tree);