On Wed, Mar 04, 2026 at 07:13:33PM +0000, Boris Staletic wrote:
> Bootstrapped and tested on x86_64-pc-linux-gnu.
> I have only ran g++.dg/reflect/* tests.
> If needed/wanted, I can run the entire `make check`, though
> that will take me the rest of the night.
> -- >8 --
> With an annotation like [[=func]] gcc ends up calling
> handle_annotation_attribute with TREE_VALUE (args) being a
> VIEW_CONVERT_EXPR, whose type is a FUNCTION_TYPE.
> That kind of annotation value should be decayed before checking
> if the type is structural.
>
> Signed-off-by: Boris Staletic <[email protected]>
>
> PR c++/124177
>
> gcc/cp/ChangeLog:
>
> * tree.cc (handle_annotation_attribute): Decay annotation
> values.
This can fit on one line (80 is the limit).
> gcc/testsuite/ChangeLog:
>
> * g++.dg/reflect/annotations11.C: New test.
> ---
> gcc/cp/tree.cc | 1 +
> gcc/testsuite/g++.dg/reflect/annotations11.C | 17 +++++++++++++++++
> 2 files changed, 18 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/reflect/annotations11.C
>
> diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
> index 20288ed04e..5c7df0a1d9 100644
> --- a/gcc/cp/tree.cc
> +++ b/gcc/cp/tree.cc
> @@ -5912,6 +5912,7 @@ handle_annotation_attribute (tree *node, tree
> ARG_UNUSED (name),
> *no_add_attrs = true;
> return NULL_TREE;
> }
> + TREE_VALUE (args) = decay_conversion (TREE_VALUE (args),
> tf_warning_or_error);
I'm not sure if it's reasonable to call decay_conversion on something
type-dependent, so perhaps this should be moved inside of the following
block.
But annotations are treated as late attributes so I'm not sure
how we'd get here with anything type-dependent, and I couldn't construct
such a test. Maybe the !t_d_e_p check could be dropped?
We're supposed to treat the expression as reflect_constant(arg) but
doing the whole convert_reflect_constant_arg thing here seems unpleasant.
So I think I'd just consider moving the decay_conversion call.
> if (!type_dependent_expression_p (TREE_VALUE (args)))
> {
> if (!structural_type_p (TREE_TYPE (TREE_VALUE (args))))
> diff --git a/gcc/testsuite/g++.dg/reflect/annotations11.C
> b/gcc/testsuite/g++.dg/reflect/annotations11.C
> new file mode 100644
> index 0000000000..8030960b0b
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/reflect/annotations11.C
Note that this has to be renamed to annotations12.C now.
> @@ -0,0 +1,17 @@
> +// PR c++/124177
> +// { dg-do compile { target c++26 } }
> +// { dg-additional-options "-freflection" }
> +
> +#include <meta>
> +
> +constexpr int f() { return 42; }
> +[[=f]] void g() {}
> +
> +static_assert (annotations_of (^^g).size () == 1);
> +static_assert (extract<int(*)()> (annotations_of (^^g)[0])() == 42);
> +
> +constexpr int x[5]{};
> +[[=x]] void h() {}
> +
> +static_assert (annotations_of (^^h).size () == 1);
> +static_assert (type_of (annotations_of (^^h)[0]) == ^^const int*);
> --
> 2.51.1
>
Marek