Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault on inserting function into std::pmr container #3

Open
jwt27 opened this issue Oct 16, 2021 · 1 comment
Open

Segfault on inserting function into std::pmr container #3

jwt27 opened this issue Oct 16, 2021 · 1 comment

Comments

@jwt27
Copy link

jwt27 commented Oct 16, 2021

The following code causes a segfault:

std::pmr::deque<func::function<void()>> functions { };
func::function<void()> f { [] { } };
functions.push_back(f);

However, creating a single function with the pmr allocator does not:

func::function<void()> f { std::allocator_arg, std::pmr::polymorphic_allocator<> { }, [] { } };

And this also works:

functions.push_back([] { });

Possibly related to #2 somehow, but std::pmr::polymorphic_allocator has no virtual destructor.

@jwt27
Copy link
Author

jwt27 commented Oct 17, 2021

Digging into this, I see the allocator is only "stored" by reinterpret_casting the manager in manager_storage_type. Is that an oversight or deliberate? I suppose it works for stateless allocators but not if they have any contents (or vtables). Now I'm
questioning how some of my code ever worked at all.

I suppose the solution is to use the allocator to allocate space for itself, or just add a char[] block in manager_storage_type and static_assert that the allocator does not exceed that size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant