]> gcc.gnu.org Git - gcc.git/commitdiff
Revert "c++: delayed parse DMI [PR96645]"
authorJason Merrill <jason@redhat.com>
Fri, 1 Apr 2022 13:01:30 +0000 (09:01 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 1 Apr 2022 14:00:26 +0000 (10:00 -0400)
The breakage from r12-7804 (in WebKit, particularly) is more of a can of
worms than I think we can address in GCC 12, so let's return to the GCC 11
status quo for now and try again in stage 1.

I think the change was correct for the current standard, but the standard
needs a fix in this area; this is CWG issue 2335.

PR c++/96645

This reverts commits r12-7804 and r12-7929.

gcc/cp/class.cc
gcc/cp/cp-tree.h
gcc/cp/method.cc
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp0x/nsdmi10.C
gcc/testsuite/g++.dg/ext/is_constructible7.C [deleted file]

index c75b889cb84d5e7d65486620d6a738ae3ecdd3a8..40e17140db5ed12d124d9f0409ddfb64d801d34a 100644 (file)
@@ -5415,11 +5415,10 @@ type_has_user_provided_or_explicit_constructor (tree t)
 
 /* Returns true iff class T has a non-user-provided (i.e. implicitly
    declared or explicitly defaulted in the class body) default
-   constructor.  If SYNTH, only return true if it hasn't been
-   implicitly defined yet.  */
+   constructor.  */
 
-static bool
-type_has_non_user_provided_default_constructor_1 (tree t, bool synth)
+bool
+type_has_non_user_provided_default_constructor (tree t)
 {
   if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (t))
     return false;
@@ -5432,28 +5431,12 @@ type_has_non_user_provided_default_constructor_1 (tree t, bool synth)
       if (TREE_CODE (fn) == FUNCTION_DECL
          && default_ctor_p (fn)
          && !user_provided_p (fn))
-       {
-         if (synth)
-           return !DECL_INITIAL (fn);
-         return true;
-       }
+       return true;
     }
 
   return false;
 }
 
-bool
-type_has_non_user_provided_default_constructor (tree t)
-{
-  return type_has_non_user_provided_default_constructor_1 (t, false);
-}
-
-bool
-type_has_default_ctor_to_be_synthesized (tree t)
-{
-  return type_has_non_user_provided_default_constructor_1 (t, true);
-}
-
 /* TYPE is being used as a virtual base, and has a non-trivial move
    assignment.  Return true if this is due to there being a user-provided
    move assignment in TYPE or one of its subobjects; if there isn't, then
index 02734a42f1b81687a615fa609ce2072c1387d452..2f718852ac182693f20ca16cb18925cad5d42ff0 100644 (file)
@@ -6720,7 +6720,6 @@ extern tree in_class_defaulted_default_constructor (tree);
 extern bool user_provided_p                    (tree);
 extern bool type_has_user_provided_constructor  (tree);
 extern bool type_has_non_user_provided_default_constructor (tree);
-extern bool type_has_default_ctor_to_be_synthesized (tree);
 extern bool vbase_has_user_provided_move_assign (tree);
 extern tree default_init_uninitialized_part (tree);
 extern bool trivial_default_constructor_is_constexpr (tree);
index e0fe21777302d555a9e96e77a40c9a937b511050..903ee666ef3966ef5be691d6a573acf4da666109 100644 (file)
@@ -2056,28 +2056,6 @@ assignable_expr (tree to, tree from)
   return r;
 }
 
-/* An unparsed default member initializer prevents calling a defaulted default
-   constructor; make checking std::is_constructible ill-formed until the DMI
-   has been parsed, to avoid caching the wrong value.  */
-
-static bool
-complain_about_unparsed_dmi (tree t)
-{
-  if (type_has_default_ctor_to_be_synthesized (t)
-      && TYPE_HAS_COMPLEX_DFLT (t))
-    for (tree f = TYPE_FIELDS (t); f; f = DECL_CHAIN (f))
-      if (TREE_CODE (f) == FIELD_DECL
-         && DECL_INITIAL (f)
-         && TREE_CODE (DECL_INITIAL (f)) == DEFERRED_PARSE)
-       {
-         error ("default member initializer for %qD required by %qs before "
-                "the end of its enclosing class", f, "std::is_constructible");
-         inform (location_of (f), "defined here");
-         return true;
-       }
-  return false;
-}
-
 /* The predicate condition for a template specialization
    is_constructible<T, Args...> shall be satisfied if and only if the
    following variable definition would be well-formed for some invented
@@ -2092,8 +2070,6 @@ constructible_expr (tree to, tree from)
   cp_unevaluated cp_uneval_guard;
   if (CLASS_TYPE_P (to))
     {
-      if (!from && complain_about_unparsed_dmi (to))
-       return error_mark_node;
       tree ctype = to;
       vec<tree, va_gc> *args = NULL;
       if (!TYPE_REF_P (to))
index 63c8af1c72292fbd702c56f943de0f8db2bb92b0..7e1c777364e79d3b5fe606ffeb5b0537f1b9acbb 100644 (file)
@@ -2701,8 +2701,6 @@ static tree cp_parser_late_parse_one_default_arg
   (cp_parser *, tree, tree, tree);
 static void cp_parser_late_parsing_nsdmi
   (cp_parser *, tree);
-static bool cp_parser_early_parsing_nsdmi
-  (cp_parser *, tree);
 static void cp_parser_late_parsing_default_args
   (cp_parser *, tree);
 static tree cp_parser_sizeof_operand
@@ -27480,8 +27478,7 @@ cp_parser_member_declaration (cp_parser* parser)
              if (DECL_DECLARES_FUNCTION_P (decl))
                cp_parser_save_default_args (parser, STRIP_TEMPLATE (decl));
              else if (TREE_CODE (decl) == FIELD_DECL
-                      && DECL_INITIAL (decl)
-                      && !cp_parser_early_parsing_nsdmi (parser, decl))
+                      && DECL_INITIAL (decl))
                /* Add DECL to the queue of NSDMI to be parsed later.  */
                vec_safe_push (unparsed_nsdmis, decl);
            }
@@ -32295,29 +32292,6 @@ cp_parser_late_parsing_nsdmi (cp_parser *parser, tree field)
   DECL_INITIAL (field) = def;
 }
 
-/* If the DEFERRED_PARSE for FIELD is safe to parse immediately, do so.
-   Returns true if deferred parsing is no longer needed.  */
-
-static bool
-cp_parser_early_parsing_nsdmi (cp_parser *parser, tree field)
-{
-  tree init = DECL_INITIAL (field);
-  if (TREE_CODE (init) != DEFERRED_PARSE)
-    return true;
-
-  cp_token_cache *tokens = DEFPARSE_TOKENS (init);
-  for (cp_token *p = tokens->first; p != tokens->last; ++p)
-    if (p->type == CPP_NAME
-       || p->keyword == RID_THIS
-       || p->keyword == RID_OPERATOR)
-      /* There's a name to look up or 'this', give up.  */
-      return false;
-
-  /* It's trivial, parse now.  */
-  cp_parser_late_parsing_nsdmi (parser, field);
-  return true;
-}
-
 /* FN is a FUNCTION_DECL which may contains a parameter with an
    unparsed DEFERRED_PARSE.  Parse the default args now.  This function
    assumes that the current scope is the scope in which the default
index a965f7bc33347b2f240a0efeed9bd6018e51fb85..d8588b7f29ea0a77fa5038e4c2927a50c946631b 100644 (file)
@@ -6,7 +6,7 @@ struct A1 {
     int y1 = 1;
   };
 
-  A1(const B1& opts = B1()) {}
+  A1(const B1& opts = B1()) {}  // { dg-error "default member initializer" }
 };
 
 struct A2 {
@@ -14,5 +14,5 @@ struct A2 {
     int x2, y2 = 1;
   };
 
-  A2(const B2& opts = B2()) {}
+  A2(const B2& opts = B2()) {}  // { dg-error "default member initializer" }
 };
diff --git a/gcc/testsuite/g++.dg/ext/is_constructible7.C b/gcc/testsuite/g++.dg/ext/is_constructible7.C
deleted file mode 100644 (file)
index 013a1df..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-// PR c++/96645
-// { dg-do compile { target c++11 } }
-
-template<bool B>
-struct bool_constant
-{
-  static constexpr bool value = B;
-  using type = bool_constant;
-};
-
-using true_type = bool_constant<true>;
-
-template<typename T>
-struct is_default_constructible
-  : bool_constant<__is_constructible(T)>
-{ };
-
-void testVarStruct()
-{
-  struct DataWithStruct {
-    struct A {
-      int number = 5; // compiles, if remove initialization
-    };
-
-    is_default_constructible<A>::type t = true_type{};
-  };
-}
This page took 0.120618 seconds and 5 git commands to generate.