]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/reflection: enhance splice error checking
authorMarek Polacek <polacek@redhat.com>
Wed, 28 Jan 2026 22:30:06 +0000 (17:30 -0500)
committerMarek Polacek <polacek@redhat.com>
Thu, 29 Jan 2026 13:42:04 +0000 (08:42 -0500)
As discussed in
<https://gcc.gnu.org/pipermail/gcc-patches/2026-January/705756.html>:

> Absolutely, I mean anything other than REFLECT_EXPR or error_mark_node
> should be an error.

I'm not giving another error for error_mark_node since we've already
complained (but make sure we have).

gcc/cp/ChangeLog:

* reflect.cc (class_members_of): Adjust comment.
(splice): Give an error if the expression doesn't evaluate to
a REFLECT_EXPR_P.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/reflect.cc

index 8acac9f8f0ea8bc76e3caea79bd538d7703715b8..4174c2ef855317343577ee51ece058d99fd10a04 100644 (file)
@@ -6564,7 +6564,7 @@ class_members_of (location_t loc, const constexpr_ctx *ctx, tree r,
     {
       tree m = field;
       if (TREE_CODE (field) == FIELD_DECL && DECL_ARTIFICIAL (field))
-       continue; /* Ignore bases.  */
+       continue; /* Ignore bases and the vptr.  */
       else if (DECL_SELF_REFERENCE_P (field))
        continue;
       else if (TREE_CODE (field) == TYPE_DECL)
@@ -7992,9 +7992,17 @@ splice (tree refl)
     refl = fold_non_dependent_expr (refl, tf_warning_or_error, true);
   else
     refl = cxx_constant_value (refl);
+  if (refl == error_mark_node)
+    {
+      gcc_checking_assert (seen_error ());
+      return error_mark_node;
+    }
   if (!REFLECT_EXPR_P (refl))
-    /* I don't wanna do your dirty work no more.  */
-    return error_mark_node;
+    {
+      error_at (cp_expr_loc_or_input_loc (refl), "splice argument must be an "
+               "expression of type %qs", "std::meta::info");
+      return error_mark_node;
+    }
 
   /* We are bringing some entity from the unevaluated expressions world
      to possibly outside of that, mark it used.  */