[gcc r16-7140] c++/reflection: enhance splice error checking
Marek Polacek
mpolacek@gcc.gnu.org
Thu Jan 29 13:42:47 GMT 2026
https://gcc.gnu.org/g:101f2970adc0a7ac5785e40eb8ad63facb4f582a
commit r16-7140-g101f2970adc0a7ac5785e40eb8ad63facb4f582a
Author: Marek Polacek <polacek@redhat.com>
Date: Wed Jan 28 17:30:06 2026 -0500
c++/reflection: enhance splice error checking
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>
Diff:
---
gcc/cp/reflect.cc | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
index 8acac9f8f0ea..4174c2ef8553 100644
--- a/gcc/cp/reflect.cc
+++ b/gcc/cp/reflect.cc
@@ -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. */
More information about the Gcc-cvs
mailing list