-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc++] Add move constructor & assignment to exception_ptr
#164281
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
vogelsgesang
merged 16 commits into
llvm:main
from
vogelsgesang:avogelsgesang-exceptionptr-move
Nov 3, 2025
Merged
Changes from 7 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5527b28
[libc++] Add move constructor & assignment to `exception_ptr`
vogelsgesang 36757da
Implement using `swap`
vogelsgesang 740129e
Define functions inline
vogelsgesang 8d90812
Undef `move` to fix build
vogelsgesang b106dc9
Make `swap` a non-hidden friend
vogelsgesang 1a26712
Update libcxx/include/__exception/exception_ptr.h
vogelsgesang baba555
Add test cases
vogelsgesang 2a22036
Formatting, unsupported no-exceptions, directly use `std::swap`
vogelsgesang fb3c655
Apply `std` in front of `swap` in the correct place
vogelsgesang ee4694c
Disable tests for C++03
vogelsgesang 3c910b8
Add missing new lines
vogelsgesang 510786c
Forward declare the `swap` overload
vogelsgesang 20bcce5
Fix test case file names
vogelsgesang 8a1a9cf
Fix `UNSUPPORTED` to exclude C++03 and fix docs
vogelsgesang 32a85dd
Fix modules build
vogelsgesang 268fbcf
Undo documentation update
vogelsgesang 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,6 @@ | |
|
|
||
| #include <exception> | ||
| #include <cassert> | ||
| #include <type_traits> | ||
|
|
||
| #include "test_macros.h" | ||
|
|
||
|
|
||
44 changes: 44 additions & 0 deletions
44
...test/std/language.support/support.exception/propagation/exception_ptr_move_assignment.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,44 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // <exception> | ||
|
|
||
| // typedef unspecified exception_ptr; | ||
|
|
||
| // Test the move assignment of exception_ptr | ||
|
|
||
| #include <exception> | ||
| #include <utility> | ||
| #include <cassert> | ||
|
|
||
| #include "test_macros.h" | ||
|
|
||
| int main(int, char**) | ||
philnik777 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| std::exception_ptr p = std::make_exception_ptr(42); | ||
| std::exception_ptr p2{p}; | ||
| assert(p2 == p); | ||
| // Move assignment | ||
| std::exception_ptr p3 | ||
| p3 = std::move(p2); | ||
| assert(p3 == p); | ||
| // `p2` was moved from. In libc++ it will be nullptr, but | ||
| // this is not guaranteed by the standard. | ||
| #if defined(_LIBCPP_VERSION) && !defined(_LIBCPP_ABI_MICROSOFT) | ||
| assert(p2 == nullptr); | ||
| assert(p2 == nullptr); | ||
| #endif | ||
philnik777 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| try { | ||
| std::rethrow_exception(p3); | ||
| } catch (int e) { | ||
| assert(e == 42); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
42 changes: 42 additions & 0 deletions
42
libcxx/test/std/language.support/support.exception/propagation/exception_ptr_move_ctr.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,42 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // <exception> | ||
|
|
||
| // typedef unspecified exception_ptr; | ||
|
|
||
| // Test the move constructor of exception_ptr | ||
|
|
||
| #include <exception> | ||
| #include <utility> | ||
| #include <cassert> | ||
|
|
||
| #include "test_macros.h" | ||
|
|
||
| int main(int, char**) | ||
| { | ||
| std::exception_ptr p = std::make_exception_ptr(42); | ||
| std::exception_ptr p2{p}; | ||
| assert(p2 == p); | ||
| // Move constructor | ||
| std::exception_ptr p3{std::move(p2)}; | ||
| assert(p3 == p); | ||
| // `p2` was moved from. In libc++ it will be nullptr, but | ||
| // this is not guaranteed by the standard. | ||
| #if defined(_LIBCPP_VERSION) && !defined(_LIBCPP_ABI_MICROSOFT) | ||
| assert(p2 == nullptr); | ||
| #endif | ||
|
|
||
| try { | ||
| std::rethrow_exception(p3); | ||
| } catch (int e) { | ||
| assert(e == 42); | ||
| } | ||
|
|
||
| return 0; | ||
| } |
39 changes: 39 additions & 0 deletions
39
libcxx/test/std/language.support/support.exception/propagation/exception_ptr_swap.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,39 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // <exception> | ||
|
|
||
| // typedef unspecified exception_ptr; | ||
|
|
||
| // Test swapping of exception_ptr | ||
|
|
||
| #include <exception> | ||
| #include <utility> | ||
| #include <cassert> | ||
|
|
||
| #include "test_macros.h" | ||
|
|
||
| int main(int, char**) | ||
| { | ||
| std::exception_ptr p21 = std::make_exception_ptr(42); | ||
| std::exception_ptr p42 = std::make_exception_ptr(21); | ||
| std::swap(p42, p21); | ||
|
|
||
| try { | ||
| std::rethrow_exception(p21); | ||
| } catch (int e) { | ||
| assert(e == 21); | ||
| } | ||
| try { | ||
| std::rethrow_exception(p42); | ||
| } catch (int e) { | ||
| assert(e == 42); | ||
| } | ||
|
|
||
| return 0; | ||
| } |
Oops, something went wrong.
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.