c++/reflection: fix ICE with OMP_CLAUSE [PR124227]

This test crashes with -fopenmp -freflection because consteval_only_p
gets

  <omp_clause 0x7fffe99db120
    type <tree_vec 0x7fffe982b900 length:3>
    reduction
    op-0: <var_decl 0x7fffe99d6390 acc>
    op-1: <init_expr 0x7fffe99c9870>
    op-2: <bind_expr 0x7fffe982b8a0>
    op-3: <var_decl 0x7fffe99d6428 D.2864>
    op-4:>

so it takes its type, but complete_type crashes on a TREE_VEC.

So let's handle TREE_VEC in consteval_only_p.

	PR c++/124227

gcc/cp/ChangeLog:

	* reflect.cc (consteval_only_p): Handle TREE_VEC.

gcc/testsuite/ChangeLog:

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

Reviewed-by: Jason Merrill <jason@redhat.com>
This commit is contained in:
Marek Polacek
2026-02-24 08:55:31 -05:00
parent b70d28d47a
commit 1aed3a853e
2 changed files with 23 additions and 0 deletions

View File

@@ -8086,6 +8086,14 @@ consteval_only_p (tree t)
if (!t)
return false;
if (TREE_CODE (t) == TREE_VEC)
{
for (tree arg : tree_vec_range (t))
if (arg && consteval_only_p (arg))
return true;
return false;
}
/* We need the complete type otherwise we'd have no fields for class
templates and thus come up with zilch for things like
template<typename T>

View File

@@ -0,0 +1,15 @@
// PR c++/124227
// { dg-do compile { target c++26 } }
// { dg-additional-options "-freflection -fopenmp" }
// { dg-require-effective-target fopenmp }
using b = float;
template <typename> class c {};
#pragma omp declare reduction(d : c<float> : omp_in)
auto e = [] {
c<b> acc;
#pragma omp parallel reduction(d : acc)
{
}
};