-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the _Choose_pocca_v
branch in basic_string::operator=(const&)
#4031
Merged
StephanTLavavej
merged 12 commits into
microsoft:main
from
achabense:_String_copy_assign
Sep 21, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
36de4e9
Add test coverage for non-trivial pointers
achabense af25008
Fix `basic_string::operator=(const&)`
achabense 02b66e9
Fix `basic_string::_Take_contents`
achabense 3cb5d00
[WIP] `failure was caused by allocated storage not being deallocated`…
achabense add808d
Update `operator bool()`
achabense 15e6762
cleanups
achabense d724676
Add `private:`.
StephanTLavavej 7f3ba48
`_CONSTEXPR20 friend` => `friend _CONSTEXPR20`
StephanTLavavej 33dce61
Use the primary template for when `is_void_v` is `true`.
StephanTLavavej 9daeca5
`struct` defaults to `public` inheritance.
StephanTLavavej 4a51b97
Work around VSO-1888462.
StephanTLavavej a6795f4
Restrict the MSVC workaround to C++20 compile-time.
StephanTLavavej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3052,8 +3052,9 @@ private: | |
|
||
if (_Right_data._Large_mode_engaged()) { // steal buffer | ||
_Construct_in_place(_My_data._Bx._Ptr, _Right_data._Bx._Ptr); | ||
_Right_data._Bx._Ptr = nullptr; | ||
_Swap_proxy_and_iterators(_Right); | ||
|
||
_Destroy_in_place(_Right_data._Bx._Ptr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} else { // copy small string buffer | ||
_My_data._Activate_SSO_buffer(); | ||
_Traits::copy(_My_data._Bx._Buf, _Right_data._Bx._Buf, _Right_data._Mysize + 1); | ||
|
@@ -3166,12 +3167,13 @@ public: | |
size_type _New_capacity = _Calculate_growth(_Right_size, _Small_string_capacity, _Right.max_size()); | ||
auto _Right_al_non_const = _Right_al; | ||
const pointer _New_ptr = _Allocate_for_capacity(_Right_al_non_const, _New_capacity); // throws | ||
|
||
_Traits::copy(_Unfancy(_New_ptr), _Right_ptr, _Right_size + 1); | ||
|
||
_Tidy_deallocate(); | ||
_Mypair._Myval2._Bx._Ptr = _New_ptr; | ||
_Mypair._Myval2._Mysize = _Right_size; | ||
_Mypair._Myval2._Myres = _New_capacity; | ||
_Construct_in_place(_Mypair._Myval2._Bx._Ptr, _New_ptr); | ||
_Mypair._Myval2._Mysize = _Right_size; | ||
_Mypair._Myval2._Myres = _New_capacity; | ||
_ASAN_STRING_CREATE(*this); | ||
} else { | ||
_Tidy_deallocate(); | ||
_Traits::copy(_Mypair._Myval2._Bx._Buf, _Right_ptr, _Right_size + 1); | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emm, for clarity it might be better just to put the correction_Destroy_in_place(_Right_data._Bx._Ptr);
at the original place.Update: (Not planned in this pr)
_Destroy_in_place
is typically followed by_Activate_SSO_buffer
; however in this function, the_Activate_SSO_buffer
call is put off to_Right._Tidy_init();
at the end. This suggests highly flaky maintenance state. I think we need to re-investigate the usages of_Activate_SSO_buffer
/_Tidy_init
/ ... in the codebase.Especially, I believe there is no need to call
_Activate_SSO_buffer
atbasic_string
's constructor, as the_String_val
already initialized the buffer in its ctor. However, a lot ofbasic_string
's ctor calls a_Tidy_init
, which includes a_Activate_SSO_buffer
.STL/stl/inc/xstring
Line 2284 in 8f67ece
_Destroy_in_place
is closely related to_Activate_SSO_buffer
. When switching to SSO mode both function must be called in order. However there are several places that the they are dangerously separated into different function calls. Especially, I've found another place that lacks_Destroy_in_place
. (in next comment)In short, I think we should do
_Activate_SSO_buffer
and_Destroy_in_place
only when switching back to SSO mode, and the two functions are so closely related that they should not be separated into different functions. As this pr shows, the separation can result in maintenance burden and has become a source of bugs.