Hi!

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).

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2026-01-28  Jakub Jelinek  <[email protected]>

        PR c++/123866
        * reflect.cc (eval_annotations_of): Use maybe_get_first_fn.

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

--- gcc/cp/reflect.cc.jj        2026-01-27 10:18:31.511823519 +0100
+++ gcc/cp/reflect.cc   2026-01-28 21:04:38.561747013 +0100
@@ -3768,6 +3768,7 @@ eval_annotations_of (location_t loc, con
       type = remove_const (type);
     }
 
+  r = maybe_get_first_fn (r);
   if (kind == REFLECT_BASE)
     {
       gcc_assert (TREE_CODE (r) == TREE_BINFO);
--- gcc/testsuite/g++.dg/reflect/annotations10.C.jj     2026-01-28 
21:06:40.111767170 +0100
+++ gcc/testsuite/g++.dg/reflect/annotations10.C        2026-01-28 
21:07:15.559189792 +0100
@@ -0,0 +1,12 @@
+// PR c++/123866
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+#include <meta>
+
+struct A
+{
+  [[=1, =2]] void foo () {}
+};
+
+static_assert (annotations_of (^^A::foo).size () == 2);

        Jakub

Reply via email to