This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] CLASSTYPE_DESTRUCTOR


There can only be one destructor, so CLASSTYPE_DESTRUCTORS is a confusing name. (we're not talking about the various flavours of the single destructor)

Applied.

nathan
--
Nathan Sidwell
2017-06-27  Nathan Sidwell  <nathan@acm.org>

	* cp-tree.h (CLASSTYPE_DESTRUCTORS): Rename to ...
	(CLASSTYPE_DESTRUCTOR): ... this.
	* class.c (accessible_nvdtor_p,
	maybe_warn_about_overly_private_class,
	add_implicitly_declared_members,
	clone_constructors_and_destructors, type_has_virtual_destructor):
	Adjust for CLASSTYPE_DESTRUCTOR.
	(deduce_noexcept_on_destructors): Absorb into ...
	(check_bases_and_members): ... here.
	* except.c (dtor_nothrow): Adjust for CLASSTYPE_DESTRUCTOR.
	* init.c (build_delete): Likewise.
	* parser.c (cp_parser_lookup_name): Likewise.
	* pt.c (check_explicit_specialization): Likewise.
	* rtti.c (emit_support_tinfos): Likewise.
	* search.c (lookup_fnfields_idx_nolazy): Likewise.

Index: class.c
===================================================================
--- class.c	(revision 249693)
+++ class.c	(working copy)
@@ -1711,7 +1711,7 @@ inherit_targ_abi_tags (tree t)
 static bool
 accessible_nvdtor_p (tree t)
 {
-  tree dtor = CLASSTYPE_DESTRUCTORS (t);
+  tree dtor = CLASSTYPE_DESTRUCTOR (t);
 
   /* An implicitly declared destructor is always public.  And,
      if it were virtual, we would have created it by now.  */
@@ -2220,7 +2220,7 @@ maybe_warn_about_overly_private_class (t
   /* Even if some of the member functions are non-private, the class
      won't be useful for much if all the constructors or destructors
      are private: such an object can never be created or destroyed.  */
-  fn = CLASSTYPE_DESTRUCTORS (t);
+  fn = CLASSTYPE_DESTRUCTOR (t);
   if (fn && TREE_PRIVATE (fn))
     {
       warning (OPT_Wctor_dtor_privacy,
@@ -3366,18 +3366,17 @@ add_implicitly_declared_members (tree t,
 				 int cant_have_const_cctor,
 				 int cant_have_const_assignment)
 {
-  bool move_ok = false;
+  /* Destructor.  */
+  if (!CLASSTYPE_DESTRUCTOR (t))
+    /* In general, we create destructors lazily.  */
+    CLASSTYPE_LAZY_DESTRUCTOR (t) = 1;
 
-  if (cxx_dialect >= cxx11 && !CLASSTYPE_DESTRUCTORS (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))
     move_ok = true;
 
-  /* Destructor.  */
-  if (!CLASSTYPE_DESTRUCTORS (t))
-    /* In general, we create destructors lazily.  */
-    CLASSTYPE_LAZY_DESTRUCTOR (t) = 1;
-
   /* [class.ctor]
 
      If there is no user-declared constructor for a class, a default
@@ -5015,8 +5014,9 @@ clone_constructors_and_destructors (tree
      we no longer need to know that.  */
   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
     clone_function_decl (*iter, /*update_methods=*/true);
-  for (ovl_iterator iter (CLASSTYPE_DESTRUCTORS (t)); iter; ++iter)
-    clone_function_decl (*iter, /*update_methods=*/true);
+
+  if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
+    clone_function_decl (dtor, /*update_methods=*/true);
 }
 
 /* Deduce noexcept for a destructor DTOR.  */
@@ -5029,24 +5029,6 @@ deduce_noexcept_on_destructor (tree dtor
 						noexcept_deferred_spec);
 }
 
-/* For each destructor in T, deduce noexcept:
-
-   12.4/3: A declaration of a destructor that does not have an
-   exception-specification is implicitly considered to have the
-   same exception-specification as an implicit declaration (15.4).  */
-
-static void
-deduce_noexcept_on_destructors (tree t)
-{
-  /* If for some reason we don't have a CLASSTYPE_METHOD_VEC, we bail
-     out now.  */
-  if (!CLASSTYPE_METHOD_VEC (t))
-    return;
-
-  for (ovl_iterator iter (CLASSTYPE_DESTRUCTORS (t)); iter; ++iter)
-    deduce_noexcept_on_destructor (*iter);
-}
-
 /* Subroutine of set_one_vmethod_tm_attributes.  Search base classes
    of TYPE for virtual functions which FNDECL overrides.  Return a
    mask of the tm attributes found therein.  */
@@ -5460,7 +5442,7 @@ type_has_virtual_destructor (tree type)
     return false;
 
   gcc_assert (COMPLETE_TYPE_P (type));
-  dtor = CLASSTYPE_DESTRUCTORS (type);
+  dtor = CLASSTYPE_DESTRUCTOR (type);
   return (dtor && DECL_VIRTUAL_P (dtor));
 }
 
@@ -5851,10 +5833,11 @@ check_bases_and_members (tree t)
      of potential interest.  */
   check_bases (t, &cant_have_const_ctor, &no_const_asn_ref);
 
-  /* Deduce noexcept on destructors.  This needs to happen after we've set
+  /* Deduce noexcept on destructor.  This needs to happen after we've set
      triviality flags appropriately for our bases.  */
   if (cxx_dialect >= cxx11)
-    deduce_noexcept_on_destructors (t);
+    if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
+      deduce_noexcept_on_destructor (dtor);
 
   /* Check all the method declarations.  */
   check_methods (t);
Index: cp-tree.h
===================================================================
--- cp-tree.h	(revision 249693)
+++ cp-tree.h	(working copy)
@@ -2145,11 +2145,11 @@ struct GTY(()) lang_type {
 #define CLASSTYPE_CONSTRUCTORS(NODE) \
   ((*CLASSTYPE_METHOD_VEC (NODE))[CLASSTYPE_CONSTRUCTOR_SLOT])
 
-/* A FUNCTION_DECL for the destructor for NODE.  These are the
+/* A FUNCTION_DECL for the destructor for NODE.  This is the
    destructors that take an in-charge parameter.  If
    CLASSTYPE_LAZY_DESTRUCTOR is true, then this entry will be NULL
    until the destructor is created with lazily_declare_fn.  */
-#define CLASSTYPE_DESTRUCTORS(NODE) \
+#define CLASSTYPE_DESTRUCTOR(NODE) \
   (CLASSTYPE_METHOD_VEC (NODE)						      \
    ? (*CLASSTYPE_METHOD_VEC (NODE))[CLASSTYPE_DESTRUCTOR_SLOT]		      \
    : NULL_TREE)
@@ -2179,11 +2179,9 @@ struct GTY(()) lang_type {
 
 /* The type corresponding to NODE when NODE is used as a base class,
    i.e., NODE without virtual base classes or tail padding.  */
-
 #define CLASSTYPE_AS_BASE(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->as_base)
 
 /* True iff NODE is the CLASSTYPE_AS_BASE version of some type.  */
-
 #define IS_FAKE_BASE_TYPE(NODE)					\
   (TREE_CODE (NODE) == RECORD_TYPE				\
    && TYPE_CONTEXT (NODE) && CLASS_TYPE_P (TYPE_CONTEXT (NODE))	\
Index: except.c
===================================================================
--- except.c	(revision 249693)
+++ except.c	(working copy)
@@ -218,7 +218,7 @@ dtor_nothrow (tree type)
   if (CLASSTYPE_LAZY_DESTRUCTOR (type))
     lazily_declare_fn (sfk_destructor, type);
 
-  return TREE_NOTHROW (CLASSTYPE_DESTRUCTORS (type));
+  return TREE_NOTHROW (CLASSTYPE_DESTRUCTOR (type));
 }
 
 /* Build up a call to __cxa_end_catch, to destroy the exception object
Index: init.c
===================================================================
--- init.c	(revision 249693)
+++ init.c	(working copy)
@@ -4580,8 +4580,7 @@ build_delete (tree otype, tree addr, spe
 	           && MAYBE_CLASS_TYPE_P (type) && !CLASSTYPE_FINAL (type)
 		   && TYPE_POLYMORPHIC_P (type))
 	    {
-	      tree dtor;
-	      dtor = CLASSTYPE_DESTRUCTORS (type);
+	      tree dtor = CLASSTYPE_DESTRUCTOR (type);
 	      if (!dtor || !DECL_VINDEX (dtor))
 		{
 		  if (CLASSTYPE_PURE_VIRTUALS (type))
@@ -4671,7 +4670,7 @@ build_delete (tree otype, tree addr, spe
       /* If the destructor is non-virtual, there is no deleting
 	 variant.  Instead, we must explicitly call the appropriate
 	 `operator delete' here.  */
-      else if (!DECL_VIRTUAL_P (CLASSTYPE_DESTRUCTORS (type))
+      else if (!DECL_VIRTUAL_P (CLASSTYPE_DESTRUCTOR (type))
 	       && auto_delete == sfk_deleting_destructor)
 	{
 	  /* We will use ADDR multiple times so we must save it.  */
Index: parser.c
===================================================================
--- parser.c	(revision 249693)
+++ parser.c	(working copy)
@@ -25679,12 +25679,14 @@ cp_parser_lookup_name (cp_parser *parser
       /* If that's not a class type, there is no destructor.  */
       if (!type || !CLASS_TYPE_P (type))
 	return error_mark_node;
+
       if (CLASSTYPE_LAZY_DESTRUCTOR (type))
 	lazily_declare_fn (sfk_destructor, type);
-      if (!CLASSTYPE_DESTRUCTORS (type))
-	  return error_mark_node;
-      /* If it was a class type, return the destructor.  */
-      return CLASSTYPE_DESTRUCTORS (type);
+
+      if (tree dtor = CLASSTYPE_DESTRUCTOR (type))
+	return dtor;
+
+      return error_mark_node;
     }
 
   /* By this point, the NAME should be an ordinary identifier.  If
Index: pt.c
===================================================================
--- pt.c	(revision 249693)
+++ pt.c	(working copy)
@@ -2884,7 +2884,7 @@ check_explicit_specialization (tree decl
 	      int is_constructor = DECL_CONSTRUCTOR_P (decl);
 
 	      if (is_constructor ? !TYPE_HAS_USER_CONSTRUCTOR (ctype)
-		  : !CLASSTYPE_DESTRUCTORS (ctype))
+		  : !CLASSTYPE_DESTRUCTOR (ctype))
 		{
 		  /* From [temp.expl.spec]:
 
Index: rtti.c
===================================================================
--- rtti.c	(revision 249693)
+++ rtti.c	(working copy)
@@ -1556,7 +1556,7 @@ emit_support_tinfos (void)
   bltn_type = TREE_TYPE (bltn_type);
   if (!COMPLETE_TYPE_P (bltn_type))
     return;
-  tree dtor = CLASSTYPE_DESTRUCTORS (bltn_type);
+  tree dtor = CLASSTYPE_DESTRUCTOR (bltn_type);
   if (!dtor || DECL_EXTERNAL (dtor))
     return;
 
Index: search.c
===================================================================
--- search.c	(revision 249693)
+++ search.c	(working copy)
@@ -1592,7 +1592,7 @@ lookup_fnfields_idx_nolazy (tree type, t
   /* and destructors are second.  */
   if (name == dtor_identifier)
     {
-      fn = CLASSTYPE_DESTRUCTORS (type);
+      fn = CLASSTYPE_DESTRUCTOR (type);
       return fn ? CLASSTYPE_DESTRUCTOR_SLOT : -1;
     }
   if (IDENTIFIER_CONV_OP_P (name))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]