From d08fb83ec697bc256c0508f4b272991868a6ff6b Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sat, 3 Jan 2026 16:18:48 +0100 Subject: [PATCH] Don't try to instantiate REFLECT_EXPR_HANDLE of REFLECT_ANNOTATION REFLECT_EXPR. --- gcc/cp/pt.cc | 5 +++++ gcc/testsuite/g++.dg/reflect/annotations8.C | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 gcc/testsuite/g++.dg/reflect/annotations8.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 33efff02aaa..4ccf16061a6 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -23016,6 +23016,11 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) reflect_kind kind = REFLECT_EXPR_KIND (t); if (TYPE_P (h) || TREE_CODE (h) == NAMESPACE_DECL) h = tsubst (h, args, complain, in_decl); + else if (kind == REFLECT_ANNOTATION) + /* annotations_of should be called on reflections of already + instantiated entities and so no need to tsubst the annotation + attribute and we rely on pointer equality of that. */ + ; else { /* [expr.reflect] The id-expression of a reflect-expression is diff --git a/gcc/testsuite/g++.dg/reflect/annotations8.C b/gcc/testsuite/g++.dg/reflect/annotations8.C new file mode 100644 index 00000000000..100ea20b681 --- /dev/null +++ b/gcc/testsuite/g++.dg/reflect/annotations8.C @@ -0,0 +1,16 @@ +// { dg-do compile { target c++26 } } +// { dg-additional-options "-freflection" } + +#include + +struct [[=42]] A {}; +template +inline auto b = [] (auto &&x) { x.template operator () (); }; + +int +main () +{ + auto l = [&] {}; + auto w = b ; + w (l); +}