Skip to content

Using the same registry with classess from two translation units inside namespace{} each and with the same name leads to errors #1236

Open
@Maykeye

Description

@Maykeye

Initially I had two separate files for catch2.
Both have their own definition of the "same" named class which is placed inside namespace{}, so my thought was it shouldn't be too same

Both files use the same registry instance, clearing it all via ".clear" method.

In my case wtih lots of files I get error like this when I try to call a view in one file even though it no entity

tests: /home/fella/src/ZZZ/entt/single_include/entt/entt.hpp:22329: entt::basic_storage_view<entt::basic_sparse_set<>, entt::deletion_policy::in_place>::basic_storage_view(const Type *) [Type = entt::basic_sparse_set<>, Policy = entt::deletion_policy::in_place]: Assertion `((leading->policy() == Policy) && ("Unexpected storage policy"))' failed.

I tried to simplify but couldn't get exact error, though I managed to get sigsegv:

$  sh ./ab.sh
=== AB.SH
echo "=== AB.SH"
cat ab.sh
echo "=== A.CPP"
cat a.cpp
echo "=== B.CPP"
cat b.cpp
clang++ -c -O1 a.cpp -o /tmp/a.o
clang++ -c -O1 b.cpp -o /tmp/b.o
clang++ -O1 /tmp/a.o /tmp/b.o -o/tmp/ab
/tmp/ab
=== A.CPP
#include "entt/single_include/entt/entt.hpp"
#include <iostream>

void run_b();

entt::registry &reset_world() {
    static entt::registry world;
    world.clear();
    return world;
}

namespace {
struct FooBar {
    std::vector<float> fff = {};
    float f = 123.0;
};
} // namespace

void run_a() {
    std::cout << "A\n";
    auto &r = reset_world();
    auto e = r.create();
    r.emplace<FooBar>(e);
    auto v = r.view<FooBar>();
}

int main() {
    run_a();
    run_b();
    run_a();
    run_b();
}
=== B.CPP
#include "entt/single_include/entt/entt.hpp"
#include <iostream>

entt::registry &reset_world();

namespace {
struct FooBar {
    char a = 0;
    int b = 1;
    std::vector<int> c = {};
};
} // namespace

void run_b() {
    std::cout << "B\n";
    auto &r = reset_world();
    auto e = r.create();
    r.emplace<FooBar>(e);
    auto v = r.view<FooBar>();
}
A
B
A
./ab.sh: line 10: 496369 Segmentation fault      (core dumped) /tmp/ab

Error goes away if I rename a class.
Error goes away if I completely recreate a registry
Error goes away if I give explicit different names to namespaces

However if I try to have "private local" components I get the error both g++ (GCC) 14.2.1 20250207 and clang version 19.1.7 in

EnTTT is 4d3e116

Can EnTT be made to see namespace{} classes with the same name as different classes?

Metadata

Metadata

Assignees

Labels

triagepending issue, PR or whatever

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions