]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: explicit object cleanups
authorJason Merrill <jason@redhat.com>
Tue, 9 Jan 2024 21:00:52 +0000 (16:00 -0500)
committerJason Merrill <jason@redhat.com>
Tue, 9 Jan 2024 21:04:09 +0000 (16:04 -0500)
The FIXME in xobj_iobj_parameters_correspond was due to expecting
TYPE_MAIN_VARIANT to be the same for all equivalent types, which is not the
case.  And I adjusted some comments that I disagree with; the iobj parameter
adjustment only applies to overload resolution, we can handle that in
cand_parms_match (and I have WIP for that).

gcc/cp/ChangeLog:

* call.cc (build_over_call): Refactor handle_arg lambda.
* class.cc (xobj_iobj_parameters_correspond): Fix FIXME.
* method.cc (defaulted_late_check): Adjust comments.

gcc/cp/call.cc
gcc/cp/class.cc
gcc/cp/method.cc

index dca8e5090e2677fb46ca7672e96a7d94f505bf30..7d3d67600c8f5050caff213e38aee02c16a40cba 100644 (file)
@@ -10187,11 +10187,11 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
       parm = TREE_CHAIN (parm);
     }
 
-  auto handle_arg = [fn, flags, complain](tree type,
-                                         tree arg,
-                                         int const param_index,
-                                         conversion *conv,
-                                         bool const conversion_warning)
+  auto handle_arg = [fn, flags](tree type,
+                               tree arg,
+                               int const param_index,
+                               conversion *conv,
+                               tsubst_flags_t const arg_complain)
     {
       /* Set user_conv_p on the argument conversions, so rvalue/base handling
         knows not to allow any more UDCs.  This needs to happen after we
@@ -10199,9 +10199,6 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
       if (flags & LOOKUP_NO_CONVERSION)
        conv->user_conv_p = true;
 
-      tsubst_flags_t const arg_complain
-       = conversion_warning ? complain : complain & ~tf_warning;
-
       if (arg_complain & tf_warning)
        maybe_warn_pessimizing_move (arg, type, /*return_p=*/false);
 
@@ -10214,13 +10211,12 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
   if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
     {
       gcc_assert (cand->num_convs > 0);
-      static constexpr bool conversion_warning = true;
       tree object_arg = consume_object_arg ();
       val = handle_arg (TREE_VALUE (parm),
                        object_arg,
                        param_index++,
                        convs[conv_index++],
-                       conversion_warning);
+                       complain);
 
       if (val == error_mark_node)
        return error_mark_node;
@@ -10260,11 +10256,14 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
                                        && cand->template_decl
                                        && !cand->explicit_targs);
 
+      tsubst_flags_t const arg_complain
+       = conversion_warning ? complain : complain & ~tf_warning;
+
       val = handle_arg (TREE_VALUE (parm),
                        current_arg,
                        param_index,
                        convs[conv_index],
-                       conversion_warning);
+                       arg_complain);
 
       if (val == error_mark_node)
        return error_mark_node;
@@ -10273,7 +10272,8 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
     }
 
   /* Default arguments */
-  for (; parm && parm != void_list_node; parm = TREE_CHAIN (parm), param_index++)
+  for (; parm && parm != void_list_node;
+       parm = TREE_CHAIN (parm), param_index++)
     {
       if (TREE_VALUE (parm) == error_mark_node)
        return error_mark_node;
index f3cfa9f0f23acb875654039e038d795ae55685ba..e5e609badf3d2c39f6447373d8faa362ff58da07 100644 (file)
@@ -1020,9 +1020,12 @@ modify_vtable_entry (tree t,
 
 \f
 /* Check if the object parameters of an xobj and iobj member function
-   correspond. This function assumes that the iobj parameter has been correctly
-   adjusted when the function is introduced by a using declaration per
-   [over.match.funcs.general.4].  */
+   correspond.  This function assumes that the iobj parameter has been
+   correctly adjusted when the function is introduced by a using declaration
+   per [over.match.funcs.general.4].
+
+   ??? But it isn't, that's only considered at overload resolution time.
+   cand_parms_match will probably need to check cand->conversion_path.  */
 
 bool
 xobj_iobj_parameters_correspond (tree fn1, tree fn2)
@@ -1112,29 +1115,10 @@ xobj_iobj_parameters_correspond (tree fn1, tree fn2)
      handles xobj parameters of pointer type, we don't have to explicitly
      check for that case.  */
 
-  /* FIXME:
-
-     template<typename>
-     struct S;
-
-     template<typename>
-     struct B {
-       int f(this S<void>&) requires true { return 5; }
-     };
-
-     template<typename>
-     struct S : B<void> {
-       using B<void>::f;
-       int f() { return 10; }
-     };
-
-     This case is broken, the incomplete type seems to screw with things.
-     I'm not sure how to fix that so I'm just noting the issue here, I have a
-     feeling it's trivial to do if you know how.  */
-
-  if (TYPE_MAIN_VARIANT (iobj_param_type)
-      != TYPE_MAIN_VARIANT (non_reference (xobj_param)))
+  if (!same_type_ignoring_top_level_qualifiers_p
+      (iobj_param_type, non_reference (xobj_param)))
     return false;
+
   /* We don't get to bail yet even if we have a by-value xobj parameter,
      a by-value xobj parameter can correspond to an iobj parameter provided the
      iobj member function is not declared with a reference qualifier.
@@ -8976,9 +8960,9 @@ resolve_address_of_overloaded_function (tree target_type,
         documentation for -fms-extensions states it's purpose is to support
         the use of microsoft headers.  Until otherwise demonstrated, we should
         assume xobj member functions are not used in this manner in microsoft
-        headers and indiscriminately forbid the incorrect syntax instead of
-        supporting it for non-legacy uses.  This should hopefully encourage
-        conformance going forward.
+        headers and forbid the incorrect syntax instead of supporting it for
+        non-legacy uses.  This should hopefully encourage conformance going
+        forward.
         This comment is referred to in typeck.cc:cp_build_addr_expr_1.  */
       if (DECL_IOBJ_MEMBER_FUNCTION_P (fn) && flag_ms_extensions)
        /* Early escape.  */;
index da6a08a03046da41972602c28c68a062540614a3..6a9f03eb8f3cd0cb5855e46293d0b5d97c235594 100644 (file)
@@ -3400,8 +3400,7 @@ defaulted_late_check (tree fn)
            || TYPE_REF_IS_RVALUE (fn_obj_ref_type))
          return false;
        /* If implicit_fn's object parameter is not a pointer, something is not
-          right.  (Or we have finally changed the type of the iobj parameter
-          in iobj member functions.)  */
+          right.  */
        gcc_assert (TYPE_PTR_P (TREE_VALUE (implicit_fn_parms)));
        /* Strip the reference/pointer off each object parameter before
           comparing them.  */
@@ -3422,10 +3421,6 @@ defaulted_late_check (tree fn)
     {
       error ("defaulted declaration %q+D does not match the "
             "expected signature", fn);
-      /* FIXME: If the user is defaulting an xobj member function we should
-        emit an xobj member function for a signature.  When we do this, maybe
-        we can just synthesize implicit_fn as an xobj member function and
-        avoid the dance in compare_fn_parms.  */
       inform (DECL_SOURCE_LOCATION (fn),
              "expected signature: %qD", implicit_fn);
     }