Repository navigation
Test allocators for being self-rebindable - #6542
AlexGuteniev wants to merge 8 commits into
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
🟡 Changes recommended
The allocator probe still imposes rebinding requirements when enforcement is disabled and misses allocators whose direct self-rebind changes type, causing compatibility failures and incomplete validation.
2 open issues
What changed in this PR
Adds compile-time allocator self-rebinding checks to STL containers, addressing issue #213 by detecting allocators that lose their original type after rebinding.
Changes:
- Introduces a shared allocator round-trip rebinding trait.
- Adds assertions across sequence and associative containers, including
basic_stringandvector<bool>. - Adds a default-enabled enforcement configuration macro.
| File | Description |
|---|---|
stl/inc/yvals_core.h |
Defines the enforcement configuration macro. |
stl/inc/xstring |
Adds the check to basic_string. |
stl/inc/xmemory |
Defines the shared rebinding probe and trait. |
stl/inc/vector |
Adds checks to vector, including vector<bool>. |
stl/inc/unordered_set |
Adds checks to unordered set containers. |
stl/inc/unordered_map |
Adds checks to unordered map containers. |
stl/inc/set |
Adds checks to set and multiset. |
stl/inc/map |
Adds checks to map and multimap. |
stl/inc/list |
Adds the check to list. |
stl/inc/forward_list |
Adds the check to forward_list. |
stl/inc/deque |
Adds the check to deque. |
Review effort: Balanced
|
|
||
| template <class _Alloc> | ||
| constexpr bool _Is_self_rebindable = | ||
| is_same_v<_Alloc, _Rebind_alloc_t<_Rebind_alloc_t<_Alloc, _Rebind_test>, typename _Alloc::value_type>>; |
There was a problem hiding this comment.
I don't know if we want this check. The issue does not ask for that.
There was a problem hiding this comment.
🟡 Changes recommended
Setting _ENFORCE_SELF_REBINDABLE_ALLOCATORS=0 removes _Self_rebindable_check while container assertions still reference it, causing compilation failures even with std::allocator instead of disabling the check.
2 open issues
1 resolved since last review
Review effort: Balanced
…k defined when enforcement is disabled' Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed to evaluate the untested allocator round-trip rejection and opt-out behavior, since existing tests cover only successful rebinds.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
This comment was marked as resolved.
This comment was marked as resolved.
|
(1) It's not enough for self-rebinding to produce the correct type. The allocator must be constructible in each step (X => Y => X). (2) I fear that this will reveal an incredible amount of misuse throughout the ecosystem. Even skilled developers are frequently terrible about writing allocators. Many just derive from It might be the case that our usage, which (almost?) always rebinds, ends up diagnosing really bad allocators already, but I've seen a lot of misuse that's gotten into production, so it seems like this PR would be a heavy lift to land. Basically, the code change in this PR is 5% of the work, the ecosystem cleanup is the remaining 95%. That said, I won't reject it outright, but I probably won't be able to land this soon. I may need to scout out RWC, dump a big list of problems here, and ask you (or other contributors) to drive fixes upstream before we can do this. |
A less aggressive approach is to enforce the check only if |
Ok, this seems to make libc++ test pass without escape. But is this a useful enforcement then? |
|
Anyway, |


Resolves #213