From: Jakub Jelinek Date: Thu, 29 Jan 2026 11:34:59 +0000 (+0100) Subject: c++: Fix ICE in eval_annotations_of [PR123866] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f2a04726b97a79f5c0cdb4af8e589aebefea7ef;p=thirdparty%2Fgcc.git c++: Fix ICE in eval_annotations_of [PR123866] eval_annotations_of throws if the passed in reflection handle is not eval_is_function (and various others). Now, eval_is_function uses maybe_get_first_fn to look through BASELINK/OVERLOAD etc., but eval_annotations_of wasn't doing that and ICEd on else if (TYPE_P (r)) r = TYPE_ATTRIBUTES (r); else if (DECL_P (r)) r = DECL_ATTRIBUTES (r); else gcc_unreachable (); because r isn't a decl nor type (nor REFLECT_BASE earlier). 2026-01-29 Jakub Jelinek PR c++/123866 * reflect.cc (eval_annotations_of): Use maybe_get_first_fn. * g++.dg/reflect/annotations10.C: New test. --- diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc index bdeec2f0f38..8acac9f8f0e 100644 --- a/gcc/cp/reflect.cc +++ b/gcc/cp/reflect.cc @@ -3768,6 +3768,7 @@ eval_annotations_of (location_t loc, const constexpr_ctx *ctx, tree r, type = remove_const (type); } + r = maybe_get_first_fn (r); if (kind == REFLECT_BASE) { gcc_assert (TREE_CODE (r) == TREE_BINFO); diff --git a/gcc/testsuite/g++.dg/reflect/annotations10.C b/gcc/testsuite/g++.dg/reflect/annotations10.C new file mode 100644 index 00000000000..e78a7d46e5e --- /dev/null +++ b/gcc/testsuite/g++.dg/reflect/annotations10.C @@ -0,0 +1,12 @@ +// PR c++/123866 +// { dg-do compile { target c++26 } } +// { dg-additional-options "-freflection" } + +#include + +struct A +{ + [[=1, =2]] void foo () {} +}; + +static_assert (annotations_of (^^A::foo).size () == 2);