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