-
Notifications
You must be signed in to change notification settings - Fork 1.6k
partial_sort_copy bugfix #1088
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
Merged
StephanTLavavej
merged 5 commits into
microsoft:master
from
CaseyCarter:partial_sort_copy_fix
Aug 9, 2020
Merged
partial_sort_copy bugfix #1088
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
46dd1c7
partial_sort_copy bugfix
CaseyCarter f0f9857
STL's review comments
CaseyCarter d5e542d
Merge branch 'master' into partial_sort_copy_fix
CaseyCarter d67a7d0
Address final? review comments
CaseyCarter c1336c8
Use dst_size
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 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| RUNALL_INCLUDE ..\usual_matrix.lst |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| // GH-1086: "std::partial_sort_copy performs an unconstrained operation" | ||
| // partial_sort_copy was constructing an object of the source range's value type | ||
| // from the result of dereferencing an iterator, which is not allowed by the | ||
| // specification of the algorithm. | ||
|
|
||
| #include <algorithm> | ||
| #include <cassert> | ||
| #include <iterator> | ||
|
|
||
| using namespace std; | ||
|
|
||
| struct wrapper { | ||
| wrapper() = default; | ||
| constexpr explicit wrapper(int i) : x{i} {} | ||
|
|
||
| bool operator<(const wrapper& that) const { | ||
| return x < that.x; | ||
| } | ||
|
|
||
| int x; | ||
| }; | ||
|
|
||
| struct source : wrapper { | ||
| source() = default; | ||
|
|
||
| using wrapper::wrapper; | ||
|
|
||
| source(const source&) = delete; | ||
| source& operator=(const source&) = delete; | ||
| }; | ||
|
|
||
| struct target : wrapper { | ||
| target() = default; | ||
|
|
||
| using wrapper::wrapper; | ||
|
|
||
| target(target&&) = default; | ||
| target& operator=(target&&) = default; | ||
|
|
||
| target& operator=(const source& w) { | ||
| x = w.x; | ||
| return *this; | ||
| } | ||
| }; | ||
|
|
||
| int main() { | ||
| constexpr int src_size = 4; | ||
| source src[src_size]; | ||
| constexpr int dst_size = 2; | ||
| target dst[dst_size]; | ||
|
|
||
| for (int i = 0; i < src_size; ++i) { | ||
| src[i].x = src_size - 1 - i; | ||
| } | ||
|
|
||
| partial_sort_copy(begin(src), end(src), begin(dst), end(dst)); | ||
CaseyCarter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| for (int i = 0; i < dst_size; ++i) { | ||
| assert(dst[i].x == i); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.