]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Don't ICE in eval_constant_of on vars with error_mark_node type [PR125412]
authorJakub Jelinek <jakub@redhat.com>
Wed, 27 May 2026 07:26:22 +0000 (09:26 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 27 May 2026 07:27:48 +0000 (09:27 +0200)
The following testcase ICEs during error recovery, because we aren't
prepared to handle error_mark_node type.

Fixed thusly.

2026-05-27  Jakub Jelinek  <jakub@redhat.com>

PR c++/125412
* reflect.cc (process_metafunction): If ht is error_operand_p,
set *non_constant_p and return NULL_TREE.

* g++.dg/reflect/pr125412.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/reflect.cc
gcc/testsuite/g++.dg/reflect/pr125412.C [new file with mode: 0644]

index 5459c8dfbe1800de8fa01aa4cb7411e59c2a5884..34750f2aa25babeebece548947d07c3802eb9cd8 100644 (file)
@@ -7887,6 +7887,11 @@ process_metafunction (const constexpr_ctx *ctx, tree fun, tree call,
        if (*jump_target || *non_constant_p)
          return NULL_TREE;
        ht = REFLECT_EXPR_HANDLE (info);
+       if (error_operand_p (ht))
+         {
+           *non_constant_p = true;
+           return NULL_TREE;
+         }
        if (METAFN_KIND_ARG (minfo, argno) == METAFN_KIND_ARG_TINFO
            && eval_is_type (ht) != boolean_true_node)
          return throw_exception_nontype (loc, ctx, fun, non_constant_p,
diff --git a/gcc/testsuite/g++.dg/reflect/pr125412.C b/gcc/testsuite/g++.dg/reflect/pr125412.C
new file mode 100644 (file)
index 0000000..4e54ce7
--- /dev/null
@@ -0,0 +1,24 @@
+// PR c++/125412
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+#include <meta>
+
+void
+foo ()
+{
+}
+
+auto bar ();
+
+template <typename T>
+auto a = foo ();       // { dg-error "variable or field 'a' declared void" }
+template <typename T>
+auto b = bar ();       // { dg-error "use of 'auto bar\\\(\\\)' before deduction of 'auto'" }
+
+consteval {
+  auto c = substitute (^^a, { ^^int });
+  std::meta::extract <int> (c);
+  auto d = substitute (^^b, { ^^int });
+  std::meta::extract <int> (d);
+}