Skip to content

Leave moved-from valueless after move and move assign when allocators don't compare equal#622

Merged
jbcoe merged 2 commits intojbcoe:mainfrom
jogerh:valueless_after_move_assign
Feb 23, 2026
Merged

Leave moved-from valueless after move and move assign when allocators don't compare equal#622
jbcoe merged 2 commits intojbcoe:mainfrom
jogerh:valueless_after_move_assign

Conversation

@jogerh
Copy link
Contributor

@jogerh jogerh commented Feb 23, 2026

N5032 specifies that move constructors and move assignment operators should leave the moved-from object in a valueless state.

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/n5032.pdf

This patch fixes this when allocators don't compare equal

@jogerh jogerh requested review from Twon and jbcoe as code owners February 23, 2026 10:22
@jogerh jogerh force-pushed the valueless_after_move_assign branch from 3e37864 to da3a1c6 Compare February 23, 2026 12:32
@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.71%. Comparing base (0588bee) to head (d58038a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #622   +/-   ##
=======================================
  Coverage   98.71%   98.71%           
=======================================
  Files          14       14           
  Lines         855      859    +4     
  Branches       90       90           
=======================================
+ Hits          844      848    +4     
  Misses         11       11           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jbcoe
Copy link
Owner

jbcoe commented Feb 23, 2026

This looks great modulo some linter issues.

I think that running pre-commit and adding // NOLINT for use-after-move in the test should suffice.

@jogerh jogerh force-pushed the valueless_after_move_assign branch from 9bc850a to fdd30bd Compare February 23, 2026 18:13
This patch fixes this postcondition when allocators compare different.
This patch fixes this postcondition when allocators compare different.
@jogerh jogerh force-pushed the valueless_after_move_assign branch from fdd30bd to d58038a Compare February 23, 2026 18:14
@jbcoe jbcoe merged commit 8877b9d into jbcoe:main Feb 23, 2026
32 checks passed
@jbcoe
Copy link
Owner

jbcoe commented Feb 23, 2026

Thanks for the PR @jogerh

Do you make use of indirect or polymorphic in your code?

@jogerh
Copy link
Contributor Author

jogerh commented Feb 23, 2026

Thanks for the PR @jogerh

Do you make use of indirect or polymorphic in your code?

Thank you for approving the PR! I am not using indirect or polymorphic yet, but I would really like to try it out. I initially considered it mostly for pimpl types, but now I see that most places where I use std::unique_ptr would benefit from indirect.

@jbcoe
Copy link
Owner

jbcoe commented Feb 23, 2026

I'd be interested to see diffs if you are able to share. Thanks for the PRs!

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.

2 participants