On 3/4/26 3:29 AM, Jakub Jelinek wrote:
On Wed, Feb 25, 2026 at 08:50:40PM +0100, Jakub Jelinek wrote:
Sounds like the maybe_strip_typedefs is wrong, since reflection in general
tries to preserve aliases.

Actually the maybe_strip_typedefs call is correct, that is for the type
argument (so when it is std::meta::annotations_with_type) and the standard
says that dealias should be used
- https://eel.is/c++draft/meta.reflection#annotation-6.2
But we probably shouldn't use TYPE_ATTRIBUTES but DECL_ATTRIBUTES (TYPE_NAME 
(r))
if r is a type alias.
I'll test a patch for that separately.

Here it is.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

2026-03-04  Jakub Jelinek  <[email protected]>

        PR c++/123866
        * reflect.cc (eval_annotations_of): For type aliases look for
        annotations in DECL_ATTRIBUTES (TYPE_NAME (r)).

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

--- gcc/cp/reflect.cc.jj        2026-03-03 15:43:33.130814556 +0100
+++ gcc/cp/reflect.cc   2026-03-03 16:42:26.904622279 +0100
@@ -3799,7 +3799,12 @@ eval_annotations_of (location_t loc, con
          }
      }
    else if (TYPE_P (r))
-    r = TYPE_ATTRIBUTES (r);
+    {
+      if (typedef_variant_p (r))
+       r = DECL_ATTRIBUTES (TYPE_NAME (r));
+      else
+       r = TYPE_ATTRIBUTES (r);
+    }
    else if (DECL_P (r))
      r = DECL_ATTRIBUTES (r);
    else
--- gcc/testsuite/g++.dg/reflect/annotations11.C.jj     2026-03-03 
17:00:27.599533819 +0100
+++ gcc/testsuite/g++.dg/reflect/annotations11.C        2026-03-03 
17:00:23.275606183 +0100
@@ -0,0 +1,21 @@
+// PR c++/123866
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+#include <meta>
+
+struct [[=1, =2]] A {};
+using B [[=3, =4, =5]] = A;
+typedef A C [[=6, =7, =8, =9]];
+using D [[=10, =11, =12, =13, =14]] = const int;
+typedef volatile int E [[=15, =16, =17, =18, =19, =20]];
+
+static_assert (annotations_of (^^A).size () == 2);
+static_assert (annotations_of (^^B).size () == 3);
+static_assert (annotations_of (dealias (^^B)).size () == 2);
+static_assert (annotations_of (^^C).size () == 4);
+static_assert (annotations_of (dealias (^^C)).size () == 2);
+static_assert (annotations_of (^^D).size () == 5);
+static_assert (annotations_of (dealias (^^D)).size () == 0);
+static_assert (annotations_of (^^E).size () == 6);
+static_assert (annotations_of (dealias (^^E)).size () == 0);


        Jakub


Reply via email to