-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implement P2273R3 constexpr unique_ptr
#2582
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
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f9b3ad2
implement P2273R3 constexpr unique_ptr
fsb4000 59a76a4
skip some parts of test because it fails
fsb4000 2ca0592
typo
fsb4000 012efc8
formatting
fsb4000 868246b
unused variable
fsb4000 28ebea4
another unused variable
fsb4000 37dd7ed
various cleanups
fsb4000 93907c0
update DevCom issues numbers
fsb4000 a36face
add license
fsb4000 9875eca
update TRANSITION comment
fsb4000 84244e5
Code review feedback.
StephanTLavavej 91ea38a
Merge branch 'main' into fix2535
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
Large diffs are not rendered by default.
Oops, something went wrong.
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_latest_matrix.lst |
131 changes: 131 additions & 0 deletions
131
tests/std/tests/P2273R3_constexpr_unique_ptr/test.compile.pass.cpp
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,131 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <cassert> | ||
| #include <memory> | ||
| #include <utility> | ||
|
|
||
| using namespace std; | ||
|
|
||
| struct Dummy { | ||
| constexpr int test() const { | ||
| return 10; | ||
| } | ||
| }; | ||
|
|
||
| constexpr bool test() { | ||
| // [memory.syn] | ||
| { | ||
| auto p1 = make_unique<int>(42); | ||
| auto p2 = make_unique_for_overwrite<int>(); | ||
| swap(p1, p2); | ||
| assert(p1 == p1); | ||
| assert(p1 != p2); | ||
|
|
||
| #if defined(__EDG__) || defined(__clang__) // TRANSITION, DevCom-1436243 | ||
| auto p3 = make_unique<int[]>(10); | ||
| auto p4 = make_unique_for_overwrite<int[]>(4); | ||
| swap(p3, p4); | ||
| assert(p3 == p3); | ||
| assert(p3 != p4); | ||
| #endif // defined(__EDG__) || defined(__clang__) | ||
|
|
||
| auto p5 = unique_ptr<int>{nullptr}; | ||
| assert(p5 == nullptr); | ||
| assert(nullptr == p5); | ||
| assert(!(p5 != nullptr)); | ||
| assert(!(nullptr != p5)); | ||
| #ifndef __EDG__ // TRANSITION, DevCom-1670927 | ||
| assert(!(p5 < nullptr)); | ||
| assert(!(nullptr < p5)); | ||
| assert(p5 <= nullptr); | ||
| assert(nullptr <= p5); | ||
| assert(!(p5 > nullptr)); | ||
| assert(!(nullptr > p5)); | ||
| assert(p5 >= nullptr); | ||
| assert(nullptr >= p5); | ||
| assert((p5 <=> nullptr) == strong_ordering::equal); | ||
| assert((nullptr <=> p5) == strong_ordering::equal); | ||
| #endif // !__EDG__ | ||
| } | ||
|
|
||
| // changes in [unique.ptr.dltr.dflt] and [unique.ptr.dltr.dflt1] | ||
| // will be tested via destructors and copy assign/constructors | ||
|
|
||
| // [unique.ptr.single.general] | ||
| { | ||
| // constructors | ||
| auto p1 = unique_ptr<int>{new int{}}; | ||
| auto d1 = default_delete<int>{}; | ||
| auto p2 = unique_ptr<int>{new int{}, d1}; | ||
| auto p3 = unique_ptr<int>{new int{}, default_delete<int>{}}; | ||
| auto p4 = move(p3); | ||
| auto p5 = unique_ptr<int>{nullptr}; | ||
| auto p6 = unique_ptr<int, default_delete<int>&>{new int{}, d1}; | ||
| auto p7 = unique_ptr<int>{move(p6)}; | ||
|
|
||
| // assignment | ||
| p3 = move(p4); | ||
| auto p8 = unique_ptr<int, default_delete<int>&>{new int{}, d1}; | ||
| p7 = move(p8); | ||
| p1 = nullptr; | ||
|
|
||
| // observers | ||
| assert(*p2 == 0); | ||
| auto p9 = unique_ptr<Dummy>{new Dummy}; | ||
| assert(p9->test() == 10); | ||
| assert(p2.get() != nullptr); | ||
| [[maybe_unused]] auto& d2 = p2.get_deleter(); | ||
| [[maybe_unused]] auto& d3 = as_const(p2).get_deleter(); | ||
| auto b1 = static_cast<bool>(p2); | ||
| assert(b1); | ||
|
|
||
| // modifiers | ||
| p1.reset(); | ||
StephanTLavavej marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| p1.reset(new int{}); | ||
| auto manual_delete = p2.release(); | ||
| delete manual_delete; | ||
| p5.swap(p1); | ||
| } | ||
|
|
||
| // [unique.ptr.runtime.general] | ||
| { | ||
| // constructors | ||
| auto p1 = unique_ptr<int[]>{new int[5]}; | ||
| auto d1 = default_delete<int[]>{}; | ||
| auto p2 = unique_ptr<int[]>{new int[5], d1}; | ||
| auto p3 = unique_ptr<int[]>{new int[5], default_delete<int[]>{}}; | ||
| auto p4 = move(p1); | ||
| auto p5 = unique_ptr<int[], default_delete<int[]>&>{new int[5], d1}; | ||
| auto p6 = unique_ptr<int[]>{move(p5)}; | ||
|
|
||
| // assignment | ||
| p1 = move(p4); | ||
| auto p7 = unique_ptr<int[], default_delete<int[]>&>{new int[5], d1}; | ||
| p6 = move(p7); | ||
| p4 = nullptr; | ||
|
|
||
| // observers | ||
| p1[0] = 50; | ||
| assert(p1[0] == 50); | ||
| assert(p1.get() != nullptr); | ||
| [[maybe_unused]] auto& d2 = p1.get_deleter(); | ||
| [[maybe_unused]] auto& d3 = as_const(p1).get_deleter(); | ||
| auto b1 = static_cast<bool>(p1); | ||
| assert(b1); | ||
|
|
||
| // modifiers | ||
| auto manual_delete = p1.release(); | ||
| delete[] manual_delete; | ||
| p1.reset(new int[3]); | ||
| p1.reset(nullptr); | ||
StephanTLavavej marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| p1.reset(); | ||
| p1.swap(p4); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| static_assert(test()); | ||
|
|
||
| int main() {} // COMPILE-ONLY | ||
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
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.