/* Any reference temp has a non-trivial initializer. */
DECL_NONTRIVIALLY_INITIALIZED_P (var) = true;
- /* Don't output reflection variables. */
- if (consteval_only_p (var))
- DECL_EXTERNAL (var) = true;
-
/* If the initializer is constant, put it in DECL_INITIAL so we get
static initialization and use in constant expressions. */
init = maybe_constant_init (expr, var, /*manifestly_const_eval=*/true);
}
else
{
+ /* Don't output reflection variables. */
+ if (consteval_only_p (var))
+ DECL_EXTERNAL (var) = true;
+
rest_of_decl_compilation (var, /*toplev=*/1, at_eof);
if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
{
--- /dev/null
+// PR c++/124646
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+#include <meta>
+
+struct A { int a; };
+struct B { int b; };
+
+consteval auto nsdms(std::meta::info i) {
+ return define_static_array(nonstatic_data_members_of(i, std::meta::access_context::unchecked()));
+}
+
+consteval void print_nsdms(std::meta::info i) {
+ auto msg = std::string("members of ") + display_string_of(i) + " are:";
+ for (auto mem : nsdms(i)) {
+ msg += " ";
+ msg += display_string_of(mem);
+ }
+ __builtin_constexpr_diag(0, "", msg); // { dg-message "members of B are: B::b" }
+}
+
+consteval {
+ print_nsdms(^^A);
+ print_nsdms(^^B);
+}
--- /dev/null
+// PR c++/124645
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+#include <meta>
+
+namespace reg
+{
+template <auto namespace_info>
+struct derived_type_registry
+{
+ static consteval auto
+ reflected_types(std::meta::info scope = namespace_info)
+ {
+ std::vector<std::meta::info> infos;
+
+ for(auto member : members_of(scope, std::meta::access_context::unchecked()))
+ {
+ if (member == std::meta::info{}) continue;
+ }
+
+ return infos;
+ }
+};
+}
+
+namespace ns1 {
+ struct test {};
+}
+
+namespace ns2 {
+}
+
+static_assert(reg::derived_type_registry<^^ns1>::reflected_types().empty());
+static_assert(reg::derived_type_registry<^^ns1>::reflected_types().size() == 0);
+static_assert(reg::derived_type_registry<^^ns2>::reflected_types().empty());
+static_assert(reg::derived_type_registry<^^ns2>::reflected_types().size() == 0);