https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124200
Bug ID: 124200
Summary: [modules][reflection] members_of does not see members
of namespaces provided via modules
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: loki at loki dot codes
Target Milestone: ---
Given the following structure:
module.cppm:
```
export module moduleA;
export namespace testA
{
struct structA {};
class classA {};
}
```
main.cpp:
```
import std;
import moduleA;
namespace testB
{
struct structA { };
class classA { };
} // namespace testB
consteval std::size_t ns_member_cnt(std::meta::info nfo)
{
return std::meta::members_of(nfo,
std::meta::access_context::unchecked()).size();
}
int main()
{
static constexpr auto testA_cnt = ns_member_cnt(^^::testA);
static constexpr auto testB_cnt = ns_member_cnt(^^::testB);
static constexpr auto testA_structA_id =
std::meta::identifier_of(^^testA::structA);
std::print("number of testA members: {}\n", testA_cnt);
std::print("number of testB members: {}\n", testB_cnt);
std::print("testA::structA identifier: {}\n", testA_structA_id);
return 0;
}
```
The programm produces the following output:
```
number of testA members: 0
number of testB members: 2
testA::structA identifier: structA
```
`reflect.cc namespace_members_of()` does currently not handle `BINDING_VECTOR`
tree nodes.
`BINDING_VECTOR` uses a hash-list and is optimized for identifer based lookup,
it does not offer a practical way to iterate over all relevant members, without
doing eager loading of the whole NS.
I am willing to implement a solution, but i am unsure about the correct
approach.
In my opinion, the most effective way would be to add the relevant information
already in the CMI with `-freflection`, and avoid any lazy_loading on vector
slots during `namespace_members_of`. But i am not sure about the impact of the
other parts of reflection code and the need to handle lazy loading if `info`
object for a pending type is used.