Skip to content

Test allocators for being self-rebindable - #6542

Open
AlexGuteniev wants to merge 8 commits into
microsoft:mainfrom
AlexGuteniev:rebound
Open

AlexGuteniev wants to merge 8 commits into
microsoft:mainfrom
AlexGuteniev:rebound

Conversation

@AlexGuteniev

@AlexGuteniev AlexGuteniev commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #213

@AlexGuteniev
AlexGuteniev requested a review from a team as a code owner November 24, 2026 08:32
Copilot AI balanced review requested due to automatic review settings November 24, 2026 08:32
@github-project-automation github-project-automation Bot moved this to Copilot Review in STL Code Reviews Nov 24, 2026
@azure-pipelines

This comment was marked as resolved.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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_string and vector<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

Comment thread stl/inc/xmemory Resolved
Comment thread stl/inc/xmemory

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>>;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we want this check. The issue does not ask for that.

Copilot AI balanced review requested due to automatic review settings November 24, 2026 08:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread stl/inc/xmemory Resolved
…k defined when enforcement is disabled'

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 08:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because missing regression coverage leaves allocator rejection, opt-out behavior, and assertion enforcement unverified.

1 open issue
1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 24, 2026 08:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because the new allocator-rebinding check and its opt-out lack regression coverage for valid, broken, and otherwise ill-formed rebinding cases.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 24, 2026 09:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The opt-out flag in tests/libcxx/usual_matrix.lst is outside the quoted PM_CL value and is silently ignored, leaving enforcement enabled for the libc++ tests.

2 open issues

Review effort: Balanced

Comment thread tests/libcxx/usual_matrix.lst Resolved
Copilot AI balanced review requested due to automatic review settings November 24, 2026 09:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

@cpplearner

This comment was marked as resolved.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added the enhancement Something can be improved label Nov 24, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

(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 std::allocator.

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.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Copilot Review to Maintainer Review in STL Code Reviews Nov 24, 2026
@cpplearner

S. B. Tam (cpplearner) commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

(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 std::allocator.

A less aggressive approach is to enforce the check only if _HAS_DEPRECATED_ALLOCATOR_MEMBERS is false, in which case std::allocator doesn't have the problematic rebind member.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 05:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because focused regression coverage is missing for allocator-rebinding rejection, the enforcement bypass, and default behavior before and after C++20.

1 open issue

Review effort: Balanced

@AlexGuteniev

Copy link
Copy Markdown
Contributor Author

A less aggressive approach is to enforce the check only if _HAS_DEPRECATED_ALLOCATOR_MEMBERS is false, in which case std::allocator doesn't have the problematic rebind member.

Ok, this seems to make libc++ test pass without escape. But is this a useful enforcement then?

@frederick-vs-ja

Copy link
Copy Markdown
Contributor

Anyway, operator_hijacker_allocator seems lacking some other required functions. I'm trying to fix it in LLVM-245893.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something can be improved

Projects

Status: Maintainer Review

Development

Successfully merging this pull request may close these issues.

STL: Consider static_asserting when allocators aren't self-rebindable

5 participants