]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: fix conversion issues
authorJason Merrill <jason@redhat.com>
Tue, 24 Dec 2024 00:57:56 +0000 (19:57 -0500)
committerJason Merrill <jason@redhat.com>
Wed, 8 Jan 2025 21:34:58 +0000 (16:34 -0500)
Some issues caught by a check from another patch:

In the convert_like_internal bad_p handling, we are iterating from outside
to inside, so once we recurse into convert_like we need to stop looping.

In build_ramp_function, we're assigning REFERENCE_TYPE things, so we need to
build the assignment directly rather than rely on functions that implement
C++ semantics.

In omp_declare_variant_finalize_one, the parameter object building failed to
handle reference parms, and it seems simpler to just use build_stub_object
like other parts of the compiler.

gcc/cp/ChangeLog:

* call.cc (convert_like_internal): Add missing break.
* coroutines.cc (cp_coroutine_transform::build_ramp_function): Build
INIT_EXPR directly.
* decl.cc (omp_declare_variant_finalize_one): Use build_stub_object.

gcc/testsuite/ChangeLog:

* g++.dg/gomp/declare-variant-3.C: Don't depend on expr dump.
* g++.dg/gomp/declare-variant-5.C: Likewise.

gcc/cp/call.cc
gcc/cp/coroutines.cc
gcc/cp/decl.cc
gcc/testsuite/g++.dg/gomp/declare-variant-3.C
gcc/testsuite/g++.dg/gomp/declare-variant-5.C

index 810594f40e18d05e4e1baadebfa63818da290341..47a125120241b6d333917b0769b57390b7c98df2 100644 (file)
@@ -8581,6 +8581,7 @@ convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
                                   /*issue_conversion_warnings=*/false,
                                   /*c_cast_p=*/false, /*nested_p=*/true,
                                   complain);
+             break;
            }
          else if (t->kind == ck_user || !t->bad_p)
            {
index 18d217b0c64ac7591f346061eba682e0839944b3..1dee3d25b9b4d89ca899e007e0c47a6a6e6919d3 100644 (file)
@@ -5021,8 +5021,8 @@ cp_coroutine_transform::build_ramp_function ()
 
          if (parm.rv_ref || parm.pt_ref)
            /* Initialise the frame reference field directly.  */
-           r = cp_build_modify_expr (loc, TREE_OPERAND (fld_idx, 0),
-                                     INIT_EXPR, arg, tf_warning_or_error);
+           r = build2 (INIT_EXPR, TREE_TYPE (arg),
+                       TREE_OPERAND (fld_idx, 0), arg);
          else
            {
              r = forward_parm (arg);
index 503ecd9387e89b791dd1927ff067d522f1c24d4d..288da65fd8db82ad0fde3ea3e805d969ffbfa9a8 100644 (file)
@@ -8466,12 +8466,7 @@ omp_declare_variant_finalize_one (tree decl, tree attr)
   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
     parm = DECL_CHAIN (parm);
   for (; parm; parm = DECL_CHAIN (parm))
-    if (type_dependent_expression_p (parm))
-      vec_safe_push (args, build_constructor (TREE_TYPE (parm), NULL));
-    else if (MAYBE_CLASS_TYPE_P (TREE_TYPE (parm)))
-      vec_safe_push (args, build_local_temp (TREE_TYPE (parm)));
-    else
-      vec_safe_push (args, build_zero_cst (TREE_TYPE (parm)));
+    vec_safe_push (args, build_stub_object (TREE_TYPE (parm)));
 
   unsigned nappend_args = 0;
   tree append_args_list = TREE_CHAIN (TREE_CHAIN (chain));
@@ -8502,7 +8497,7 @@ omp_declare_variant_finalize_one (tree decl, tree attr)
              return true;
            }
          for (unsigned i = 0; i < nappend_args; i++)
-           vec_safe_push (args, build_zero_cst (TREE_TYPE (type)));
+           vec_safe_push (args, build_stub_object (TREE_TYPE (type)));
        }
     }
 
index 8044cef91f20b7ff2f9a361694d344af246e4281..376eefc2dc1f7468cc93dce7e8f05a6fa228a557 100644 (file)
@@ -86,7 +86,7 @@ struct E { int e; };
 
 void fn19 (E, int);
 
-#pragma omp declare variant (fn19)match(user={condition(0)})   // { dg-error "could not convert '0' from 'int' to 'E'" }
+#pragma omp declare variant (fn19)match(user={condition(0)})   // { dg-error {could not convert '[^']*' from 'int' to 'E'} }
 void fn20 (int, E);
 
 struct F { operator int () const { return 42; } int f; };
@@ -95,7 +95,7 @@ void fn21 (int, F);
 #pragma omp declare variant ( fn21 ) match (user = { condition ( 1 - 1 ) } )   // { dg-error "variant 'void fn21\\\(int, F\\\)' and base 'void fn22\\\(F, F\\\)' have incompatible types" }
 void fn22 (F, F);
 
-#pragma omp declare variant (fn19) match (user={condition(0)})         // { dg-error "could not convert '<anonymous>' from 'F' to 'E'" }
+#pragma omp declare variant (fn19) match (user={condition(0)})         // { dg-error {could not convert '[^']*' from 'F' to 'E'} }
 void fn23 (F, int);
 
 void fn24 (int);
index fa80c255c81460540c7c087eb0888d8561c563d3..a52fa528e1ffd5321c5629f4b80834084ccd33db 100644 (file)
@@ -74,7 +74,7 @@ struct E { int e; };
 
 void fn19 (E, int) {}
 
-#pragma omp declare variant (fn19)match(user={condition(0)})   // { dg-error "could not convert '0' from 'int' to 'E'" }
+#pragma omp declare variant (fn19)match(user={condition(0)})   // { dg-error {could not convert '[^']*' from 'int' to 'E'} }
 void fn20 (int, E) {}
 
 struct F { operator int () const { return 42; } int f; };
@@ -83,7 +83,7 @@ void fn21 (int, F) {}
 #pragma omp declare variant ( fn21 ) match (user = { condition ( 1 - 1 ) } )   // { dg-error "variant 'void fn21\\\(int, F\\\)' and base 'void fn22\\\(F, F\\\)' have incompatible types" }
 void fn22 (F, F) {}
 
-#pragma omp declare variant (fn19) match (user={condition(0)})         // { dg-error "could not convert '<anonymous>' from 'F' to 'E'" }
+#pragma omp declare variant (fn19) match (user={condition(0)})         // { dg-error {could not convert '[^']*' from 'F' to 'E'} }
 void fn23 (F, int) {}
 
 void fn24 (int);