]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: fix decltype_p handling for binary expressions
authorJason Merrill <jason@redhat.com>
Wed, 25 Jun 2025 20:26:56 +0000 (16:26 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 27 Jun 2025 19:14:25 +0000 (15:14 -0400)
With Jakub's constexpr virtual base patch,
23_containers/vector/bool/cmp_c++20.cc failed the assert I add to
fixed_type_or_null, meaning that it returned the wrong value.  Let's fix the
result as well as adding the assert, and fix cp_parser_binary_expression to
properly wrap any class-type calls in the operands in TARGET_EXPR even
within a decltype so we don't hit the assert.

gcc/cp/ChangeLog:

* class.cc (fixed_type_or_null): Handle class-type CALL_EXPR.
* parser.cc (cp_parser_binary_expression): Fix decltype_p handling.

gcc/cp/class.cc
gcc/cp/parser.cc

index f30cf3fcd095872d3c4c74e1fcd5cf71287f51a5..6cd6e8f1bfcf23b6a37758deb2a0c18b85530b29 100644 (file)
@@ -8350,6 +8350,15 @@ fixed_type_or_null (tree instance, int *nonnull, int *cdtorp)
            *nonnull = 1;
          return TREE_TYPE (instance);
        }
+      if (CLASS_TYPE_P (TREE_TYPE (instance)))
+       {
+         /* We missed a build_cplus_new somewhere, likely due to tf_decltype
+            mishandling.  */
+         gcc_checking_assert (false);
+         if (nonnull)
+           *nonnull = 1;
+         return TREE_TYPE (instance);
+       }
       return NULL_TREE;
 
     case SAVE_EXPR:
index 80fd7990bbbb840773cefba28329b6a7c50874a3..b1626acb50b7787601072b44e1f98aabf21d5ebc 100644 (file)
@@ -10835,6 +10835,14 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p,
            goto pop;
        }
 
+      /* If we skipped build_cplus_new in build_cxx_call because of decltype_p,
+        call it now that we know current.lhs is a subexpression.  */
+      if (decltype_p && !processing_template_decl
+         && TREE_CODE (current.lhs) == CALL_EXPR
+         && CLASS_TYPE_P (TREE_TYPE (current.lhs)))
+       current.lhs = build_cplus_new (TREE_TYPE (current.lhs), current.lhs,
+                                      tf_warning_or_error);
+
      get_rhs:
       current.tree_type = binops_by_token[token->type].tree_type;
       current.loc = token->location;