Skip to content

Fix unqualified swap for small_vector - #343

Merged
igaztanaga merged 1 commit into
boostorg:developfrom
monerinngu0:fix-small-vector-adl-swap
Aug 26, 2026
Merged

Fix unqualified swap for small_vector#343
igaztanaga merged 1 commit into
boostorg:developfrom
monerinngu0:fix-small-vector-adl-swap

Conversation

@monerinngu0

Copy link
Copy Markdown
Contributor

Unqualified swap(a, b) for two small_vector objects was resolved
to the hidden friend swap of the underlying vector. This caused
pointers to internal storage to be treated as dynamically allocated
storage and deallocated during destruction.

Add a hidden friend swap to small_vector that forwards to its
capacity-aware member swap.

A regression test verifies unqualified ADL swap when both vectors use
their internal storage.

Fixes #342.

@igaztanaga
igaztanaga merged commit 421cb6f into boostorg:develop Aug 26, 2026
61 checks passed
@igaztanaga

Copy link
Copy Markdown
Member

Many thanks for the fix!

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

Successfully merging this pull request may close these issues.

Using unqualified swap() on two small_vectors calls an incorrect swap function

2 participants