Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
-- >8 --
The assert in this test currently doesn't pass because .size () is 3, due to
{A, B, B} found in N, but it should only be {A, B}, because we should
skip the hidden "void N::B()".
PR c++/123641
gcc/cp/ChangeLog:
* name-lookup.cc (STAT_TYPE_HIDDEN_P, STAT_DECL_HIDDEN_P): Moved from
here to...
* name-lookup.h: ...here.
* reflect.cc (namespace_members_of): Skip STAT_TYPE_HIDDEN_P.
gcc/testsuite/ChangeLog:
* g++.dg/reflect/members_of8.C: New test.
---
gcc/cp/name-lookup.cc | 16 +++-------------
gcc/cp/name-lookup.h | 9 +++++++++
gcc/cp/reflect.cc | 2 +-
gcc/testsuite/g++.dg/reflect/members_of8.C | 17 +++++++++++++++++
4 files changed, 30 insertions(+), 14 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/reflect/members_of8.C
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 9a732e14979..c6d67a95a30 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -59,7 +59,9 @@ enum binding_slots
/* Create an overload suitable for recording an artificial TYPE_DECL
and another decl. We use this machanism to implement the struct
- stat hack. */
+ stat hack.
+ When a STAT_HACK_P is true, OVL_USING_P and OVL_EXPORT_P are valid
+ and apply to the hacked type. */
#define STAT_HACK_P(N) ((N) && TREE_CODE (N) == OVERLOAD && OVL_LOOKUP_P (N))
#define STAT_TYPE_VISIBLE_P(N) TREE_USED (OVERLOAD_CHECK (N))
@@ -69,18 +71,6 @@ enum binding_slots
#define MAYBE_STAT_DECL(N) (STAT_HACK_P (N) ? STAT_DECL (N) : N)
#define MAYBE_STAT_TYPE(N) (STAT_HACK_P (N) ? STAT_TYPE (N) : NULL_TREE)
-/* When a STAT_HACK_P is true, OVL_USING_P and OVL_EXPORT_P are valid
- and apply to the hacked type. */
-
-/* For regular (maybe) overloaded functions, we have OVL_HIDDEN_P.
- But we also need to indicate hiddenness on implicit type decls
- (injected friend classes), and (coming soon) decls injected from
- block-scope externs. It is too awkward to press the existing
- overload marking for that. If we have a hidden non-function, we
- always create a STAT_HACK, and use these two markers as needed. */
-#define STAT_TYPE_HIDDEN_P(N) OVL_HIDDEN_P (N)
-#define STAT_DECL_HIDDEN_P(N) OVL_DEDUP_P (N)
-
/* Create a STAT_HACK node with DECL as the value binding and TYPE as
the type binding. */
diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h
index 4c167cd135c..cb8ca36b2fc 100644
--- a/gcc/cp/name-lookup.h
+++ b/gcc/cp/name-lookup.h
@@ -41,6 +41,15 @@ struct cp_binding_level;
value and type slots are both filled and both hidden. */
#define HIDDEN_TYPE_BINDING_P(NODE) ((NODE)->type_is_hidden)
+/* For regular (maybe) overloaded functions, we have OVL_HIDDEN_P.
+ But we also need to indicate hiddenness on implicit type decls
+ (injected friend classes), and (coming soon) decls injected from
+ block-scope externs. It is too awkward to press the existing
+ overload marking for that. If we have a hidden non-function, we
+ always create a STAT_HACK, and use these two markers as needed. */
+#define STAT_TYPE_HIDDEN_P(N) OVL_HIDDEN_P (N)
+#define STAT_DECL_HIDDEN_P(N) OVL_DEDUP_P (N)
+
/* Datatype that represents binding established by a declaration between
a name and a C++ entity. */
struct GTY(()) cxx_binding {
diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
index 46355251bcd..066a8a73934 100644
--- a/gcc/cp/reflect.cc
+++ b/gcc/cp/reflect.cc
@@ -6482,7 +6482,7 @@ namespace_members_of (location_t loc, tree ns)
CONSTRUCTOR_APPEND_ELT (elts, NULL_TREE,
get_reflection_raw (loc, m));
}
- if (OVL_DEDUP_P (o) || !OVL_FUNCTION (o))
+ if (OVL_DEDUP_P (o) || !OVL_FUNCTION (o) || STAT_TYPE_HIDDEN_P (o))
continue;
o = OVL_FUNCTION (o);
}
diff --git a/gcc/testsuite/g++.dg/reflect/members_of8.C
b/gcc/testsuite/g++.dg/reflect/members_of8.C
new file mode 100644
index 00000000000..ec6b6fdf192
--- /dev/null
+++ b/gcc/testsuite/g++.dg/reflect/members_of8.C
@@ -0,0 +1,17 @@
+// PR c++/123641
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+// Test that we skip STAT_TYPE_HIDDEN_P.
+
+#include <meta>
+using namespace std::meta;
+
+namespace N {
+ void B ();
+ struct A {
+ int m;
+ friend class B;
+ };
+}
+constexpr access_context uctx = access_context::unchecked ();
+static_assert (members_of (^^N, uctx).size () == 2);
base-commit: 918cf3a50de02334af7bac2ad11ac89e8d816c11
--
2.53.0