[handle] guard self-assign on owning-handle assignments - #130
Open
krystophny wants to merge 1 commit into
Open
Conversation
Move-assigns (handle_heap, handle_stack, handle_sso): add EXPECTS(this != &h). EXPECTS is a no-op under NDEBUG, so release builds pay nothing on the hot path. Copy-assigns (handle_heap, handle_stack): add the standard fast-path if (this == &h) return *this; (handle_sso already has it). handle_borrowed is = default and unaffected. check_handle<H>() in nda_mem.cpp deliberately exercised self-swap and self-move-assign, both now precondition violations. Gated under #ifdef NDEBUG so release-mode coverage is preserved. Closes TRIQS#11.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11.
Add
EXPECTS(this != &h)on the move-assign operators of the threenon-defaulted owning handles (
handle_heap,handle_stack,handle_sso).Also add
if (this == &h) return *this;to the copy-assigns ofhandle_heapandhandle_stack(handle_ssoalready has it).handle_borrowedis= defaultand unaffected. EXPECTS is a no-op underNDEBUG, so release builds pay nothing on the hot path.check_handle<H>()intest/c++/nda_mem.cppdeliberately exercisedstd::swap(handle, handle)andmove1 = std::move(move1), both nowprecondition violations. Gated under
#ifdef NDEBUGso release-modecoverage is preserved.
Verification