]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/cp/class.c
Merge in trunk.
[thirdparty/gcc.git] / gcc / cp / class.c
index 9e0229fcba3708c2334d8af6f8dc5909daba463a..a0c3ab7e72b9d730992485708a77df505790842b 100644 (file)
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "splay-tree.h"
 #include "pointer-set.h"
 #include "hash-table.h"
+#include "wide-int.h"
 
 /* The number of nested classes being processed.  If we are not in the
    scope of any class, this is zero.  */
@@ -1517,6 +1518,12 @@ check_bases (tree t,
        |= CLASSTYPE_CONTAINS_EMPTY_CLASS_P (basetype);
       TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
                                    || TYPE_HAS_COMPLEX_DFLT (basetype));
+      SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT
+       (t, CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
+        | CLASSTYPE_READONLY_FIELDS_NEED_INIT (basetype));
+      SET_CLASSTYPE_REF_FIELDS_NEED_INIT
+       (t, CLASSTYPE_REF_FIELDS_NEED_INIT (t)
+        | CLASSTYPE_REF_FIELDS_NEED_INIT (basetype));
 
       /*  A standard-layout class is a class that:
          ...
@@ -4668,15 +4675,8 @@ deduce_noexcept_on_destructors (tree t)
   if (!CLASSTYPE_METHOD_VEC (t))
     return;
 
-  bool saved_nontrivial_dtor = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t);
-
-  /* Avoid early exit from synthesized_method_walk (c++/57645).  */
-  TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = true;
-
   for (tree fns = CLASSTYPE_DESTRUCTORS (t); fns; fns = OVL_NEXT (fns))
     deduce_noexcept_on_destructor (OVL_CURRENT (fns));
-
-  TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = saved_nontrivial_dtor;
 }
 
 /* Subroutine of set_one_vmethod_tm_attributes.  Search base classes
@@ -4878,7 +4878,8 @@ user_provided_p (tree fn)
     return true;
   else
     return (!DECL_ARTIFICIAL (fn)
-           && !DECL_DEFAULTED_IN_CLASS_P (fn));
+           && !(DECL_INITIALIZED_IN_CLASS_P (fn)
+                && (DECL_DEFAULTED_FN (fn) || DECL_DELETED_FN (fn))));
 }
 
 /* Returns true iff class T has a user-provided constructor.  */
@@ -5143,7 +5144,7 @@ type_has_user_declared_move_assign (tree t)
 }
 
 /* Nonzero if we need to build up a constructor call when initializing an
-   object of this class, either because it has a user-provided constructor
+   object of this class, either because it has a user-declared constructor
    or because it doesn't have a default constructor (so we need to give an
    error if no initializer is provided).  Use TYPE_NEEDS_CONSTRUCTING when
    what you care about is whether or not an object can be produced by a
@@ -5159,8 +5160,50 @@ type_build_ctor_call (tree t)
   if (TYPE_NEEDS_CONSTRUCTING (t))
     return true;
   inner = strip_array_types (t);
-  return (CLASS_TYPE_P (inner) && !TYPE_HAS_DEFAULT_CONSTRUCTOR (inner)
-         && !ANON_AGGR_TYPE_P (inner));
+  if (!CLASS_TYPE_P (inner) || ANON_AGGR_TYPE_P (inner))
+    return false;
+  if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (inner))
+    return true;
+  if (cxx_dialect < cxx11)
+    return false;
+  /* A user-declared constructor might be private, and a constructor might
+     be trivial but deleted.  */
+  for (tree fns = lookup_fnfields_slot (inner, complete_ctor_identifier);
+       fns; fns = OVL_NEXT (fns))
+    {
+      tree fn = OVL_CURRENT (fns);
+      if (!DECL_ARTIFICIAL (fn)
+         || DECL_DELETED_FN (fn))
+       return true;
+    }
+  return false;
+}
+
+/* Like type_build_ctor_call, but for destructors.  */
+
+bool
+type_build_dtor_call (tree t)
+{
+  tree inner;
+  if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
+    return true;
+  inner = strip_array_types (t);
+  if (!CLASS_TYPE_P (inner) || ANON_AGGR_TYPE_P (inner)
+      || !COMPLETE_TYPE_P (inner))
+    return false;
+  if (cxx_dialect < cxx11)
+    return false;
+  /* A user-declared destructor might be private, and a destructor might
+     be trivial but deleted.  */
+  for (tree fns = lookup_fnfields_slot (inner, complete_dtor_identifier);
+       fns; fns = OVL_NEXT (fns))
+    {
+      tree fn = OVL_CURRENT (fns);
+      if (!DECL_ARTIFICIAL (fn)
+         || DECL_DELETED_FN (fn))
+       return true;
+    }
+  return false;
 }
 
 /* Remove all zero-width bit-fields from T.  */
@@ -5783,7 +5826,7 @@ end_of_class (tree t, int include_virtuals_p)
        continue;
 
       offset = end_of_base (base_binfo);
-      if (INT_CST_LT_UNSIGNED (result, offset))
+      if (INT_CST_LT (result, offset))
        result = offset;
     }
 
@@ -5793,7 +5836,7 @@ end_of_class (tree t, int include_virtuals_p)
         vec_safe_iterate (vbases, i, &base_binfo); i++)
       {
        offset = end_of_base (base_binfo);
-       if (INT_CST_LT_UNSIGNED (result, offset))
+       if (INT_CST_LT (result, offset))
          result = offset;
       }
 
@@ -5873,7 +5916,7 @@ include_empty_classes (record_layout_info rli)
                      CLASSTYPE_AS_BASE (rli->t) != NULL_TREE);
   rli_size = rli_size_unit_so_far (rli);
   if (TREE_CODE (rli_size) == INTEGER_CST
-      && INT_CST_LT_UNSIGNED (rli_size, eoc))
+      && INT_CST_LT (rli_size, eoc))
     {
       if (!abi_version_at_least (2))
        /* In version 1 of the ABI, the size of a class that ends with
@@ -6125,7 +6168,7 @@ layout_class_type (tree t, tree *virtuals_p)
        {
          unsigned HOST_WIDE_INT width;
          tree ftype = TREE_TYPE (field);
-         width = tree_low_cst (DECL_SIZE (field), /*unsignedp=*/1);
+         width = tree_to_uhwi (DECL_SIZE (field));
          if (width != TYPE_PRECISION (ftype))
            {
              TREE_TYPE (field)
@@ -7997,7 +8040,7 @@ dump_class_hierarchy_r (FILE *stream,
   igo = TREE_CHAIN (binfo);
 
   fprintf (stream, HOST_WIDE_INT_PRINT_DEC,
-          tree_low_cst (BINFO_OFFSET (binfo), 0));
+          tree_to_shwi (BINFO_OFFSET (binfo)));
   if (is_empty_class (BINFO_TYPE (binfo)))
     fprintf (stream, " empty");
   else if (CLASSTYPE_NEARLY_EMPTY_P (BINFO_TYPE (binfo)))
@@ -8073,10 +8116,10 @@ dump_class_hierarchy_1 (FILE *stream, int flags, tree t)
 {
   fprintf (stream, "Class %s\n", type_as_string (t, TFF_PLAIN_IDENTIFIER));
   fprintf (stream, "   size=%lu align=%lu\n",
-          (unsigned long)(tree_low_cst (TYPE_SIZE (t), 0) / BITS_PER_UNIT),
+          (unsigned long)(tree_to_shwi (TYPE_SIZE (t)) / BITS_PER_UNIT),
           (unsigned long)(TYPE_ALIGN (t) / BITS_PER_UNIT));
   fprintf (stream, "   base size=%lu base align=%lu\n",
-          (unsigned long)(tree_low_cst (TYPE_SIZE (CLASSTYPE_AS_BASE (t)), 0)
+          (unsigned long)(tree_to_shwi (TYPE_SIZE (CLASSTYPE_AS_BASE (t)))
                           / BITS_PER_UNIT),
           (unsigned long)(TYPE_ALIGN (CLASSTYPE_AS_BASE (t))
                           / BITS_PER_UNIT));
@@ -8113,7 +8156,7 @@ dump_array (FILE * stream, tree decl)
   HOST_WIDE_INT elt;
   tree size = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (decl)));
 
-  elt = (tree_low_cst (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))), 0)
+  elt = (tree_to_shwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))))
         / BITS_PER_UNIT);
   fprintf (stream, "%s:", decl_as_string (decl, TFF_PLAIN_IDENTIFIER));
   fprintf (stream, " %s entries",
@@ -8202,10 +8245,10 @@ dump_thunk (FILE *stream, int indent, tree thunk)
        /*NOP*/;
       else if (DECL_THIS_THUNK_P (thunk))
        fprintf (stream, " vcall="  HOST_WIDE_INT_PRINT_DEC,
-                tree_low_cst (virtual_adjust, 0));
+                tree_to_shwi (virtual_adjust));
       else
        fprintf (stream, " vbase=" HOST_WIDE_INT_PRINT_DEC "(%s)",
-                tree_low_cst (BINFO_VPTR_FIELD (virtual_adjust), 0),
+                tree_to_shwi (BINFO_VPTR_FIELD (virtual_adjust)),
                 type_as_string (BINFO_TYPE (virtual_adjust), TFF_SCOPE));
       if (THUNK_ALIAS (thunk))
        fprintf (stream, " alias to %p", (void *)THUNK_ALIAS (thunk));