-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix thrust::optional<T&>::emplace() (#1707)
Where optional<T> inherits optional<T>::construct via a series of classes, optional<T&> does not. This means that optional<T&>::emplace() was broken and called into a member function that did not exist. This replaces the functionality to make optional<T&>::emplace() change the stored reference to the new one. Note that it does _not_ emplace the referee, as this would lead to questionable behavior when the optional holds nullopt. This was revealed by a change in LLVM, see llvm/llvm-project#90152 and ROCm/rocThrust#404.
- Loading branch information
Showing
2 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
thrust/testing/regression/gh_1706__thrust_optional_reference_emplace.cu
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <thrust/optional.h> | ||
|
||
#include <unittest/unittest.h> | ||
|
||
int main() | ||
{ | ||
{ | ||
int a = 10; | ||
|
||
thrust::optional<int&> maybe(a); | ||
|
||
int b = 20; | ||
maybe.emplace(b); | ||
|
||
ASSERT_EQUAL(maybe.value(), 20); | ||
// Emplacing with b shouldn't change a | ||
ASSERT_EQUAL(a, 10); | ||
|
||
int c = 30; | ||
maybe.emplace(c); | ||
|
||
ASSERT_EQUAL(maybe.value(), 30); | ||
ASSERT_EQUAL(b, 20); | ||
} | ||
|
||
{ | ||
thrust::optional<int&> maybe; | ||
|
||
int b = 21; | ||
maybe.emplace(b); | ||
|
||
ASSERT_EQUAL(maybe.value(), 21); | ||
|
||
int c = 31; | ||
maybe.emplace(c); | ||
|
||
ASSERT_EQUAL(maybe.value(), 31); | ||
ASSERT_EQUAL(b, 21); | ||
} | ||
} |
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