]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: avoid non-TARGET_EXPR class prvalues
authorJason Merrill <jason@redhat.com>
Thu, 6 May 2021 02:25:45 +0000 (22:25 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 7 May 2021 16:09:38 +0000 (12:09 -0400)
Around PR98469 I asked Jakub to wrap a class BIT_CAST_EXPR in TARGET_EXPR;
SPACESHIP_EXPR needs the same thing.  The dummy CAST_EXPR created in
can_convert is another instance of a non-TARGET_EXPR prvalue, so let's use
the declval-like build_stub_object there instead.

gcc/cp/ChangeLog:

* cp-tree.h (build_stub_object): Declare.
* method.c (build_stub_object): No longer static.
* call.c (can_convert): Use it.
* tree.c (build_dummy_object): Adjust comment.
* typeck.c (cp_build_binary_op): Wrap SPACESHIP_EXPR in a
TARGET_EXPR.

gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/method.c
gcc/cp/tree.c
gcc/cp/typeck.c

index 57bac05fe70bc5a73ff3223faadd033a00d06da4..d985e4e8eda95b6545acb9733b3861cbc1825032 100644 (file)
@@ -12177,7 +12177,7 @@ can_convert (tree to, tree from, tsubst_flags_t complain)
   /* implicit_conversion only considers user-defined conversions
      if it has an expression for the call argument list.  */
   if (CLASS_TYPE_P (from) || CLASS_TYPE_P (to))
-    arg = build1 (CAST_EXPR, from, NULL_TREE);
+    arg = build_stub_object (from);
   return can_convert_arg (to, from, arg, LOOKUP_IMPLICIT, complain);
 }
 
index a08867aea628cad0d8dcf2f0a954f646f2144032..122dadf976fd7d4738eb11cb198aa206bcadc484 100644 (file)
@@ -6968,6 +6968,7 @@ extern tree get_copy_ctor                 (tree, tsubst_flags_t);
 extern tree get_copy_assign                    (tree);
 extern tree get_default_ctor                   (tree);
 extern tree get_dtor                           (tree, tsubst_flags_t);
+extern tree build_stub_object                  (tree);
 extern tree strip_inheriting_ctors             (tree);
 extern tree inherited_ctor_binfo               (tree);
 extern bool base_ctor_omit_inherited_parms     (tree);
index 0f416bec35b5e562f4448b5110b64d6ae9817667..f8c9456d7204a1c5ef49e2ed83c1982941ad88c1 100644 (file)
@@ -1793,7 +1793,7 @@ build_stub_type (tree type, int quals, bool rvalue)
 /* Build a dummy glvalue from dereferencing a dummy reference of type
    REFTYPE.  */
 
-static tree
+tree
 build_stub_object (tree reftype)
 {
   if (!TYPE_REF_P (reftype))
index 3a20cd33fdc2eb0b7cd7486562e76f976ea1d24f..4ccd7a314f523a991aa62235b37c47bd3fa7d277 100644 (file)
@@ -4175,7 +4175,8 @@ member_p (const_tree decl)
 }
 
 /* Create a placeholder for member access where we don't actually have an
-   object that the access is against.  */
+   object that the access is against.  For a general declval<T> equivalent,
+   use build_stub_object instead.  */
 
 tree
 build_dummy_object (tree type)
index 50d0f1e6a62aa402c5f16626ec435073c753b009..5af47ce89a94f288b2a3dfded8f2ab6338d3767c 100644 (file)
@@ -5931,6 +5931,8 @@ cp_build_binary_op (const op_location_t &location,
 
   if (!processing_template_decl)
     {
+      if (resultcode == SPACESHIP_EXPR)
+       result = get_target_expr_sfinae (result, complain);
       op0 = cp_fully_fold (op0);
       /* Only consider the second argument if the first isn't overflowed.  */
       if (!CONSTANT_CLASS_P (op0) || TREE_OVERFLOW_P (op0))