Skip to content

Commit

Permalink
Fix read of dangling reference (#2290)
Browse files Browse the repository at this point in the history
Fixes: #2289
  • Loading branch information
bernhardmgruber committed Aug 26, 2024
1 parent 03247ab commit 9d4c3a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
23 changes: 10 additions & 13 deletions thrust/testing/functional_placeholders_miscellaneous.cu
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,14 @@ VectorUnitTest<TestFunctionalPlaceholdersTransformIterator,
VectorUnitTest<TestFunctionalPlaceholdersTransformIterator, ThirtyTwoBitTypes, thrust::host_vector, std::allocator>
TestFunctionalPlaceholdersTransformIteratorInstanceHost;

template <typename T>
struct TestFunctionalPlaceholdersArgumentValueCategories
void TestFunctionalPlaceholdersArgumentValueCategories()
{
void operator()() const
{
using namespace thrust::placeholders;
auto expr = _1 * _1 + _2 * _2;
T a = 2;
T b = 3;
ASSERT_ALMOST_EQUAL(expr(2, 3), 13); // pass pr-value
ASSERT_ALMOST_EQUAL(expr(a, b), 13); // pass l-value
ASSERT_ALMOST_EQUAL(expr(::cuda::std::move(a), ::cuda::std::move(b)), 13); // pass x-value
}
};
using namespace thrust::placeholders;
auto expr = _1 * _1 + _2 * _2;
int a = 2;
int b = 3;
ASSERT_EQUAL(expr(2, 3), 13); // pass pr-value
ASSERT_EQUAL(expr(a, b), 13); // pass l-value
ASSERT_EQUAL(expr(::cuda::std::move(a), ::cuda::std::move(b)), 13); // pass x-value
}
DECLARE_UNITTEST(TestFunctionalPlaceholdersArgumentValueCategories);
4 changes: 2 additions & 2 deletions thrust/thrust/detail/functional/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ struct argument
{
template <typename... Ts>
_CCCL_HOST_DEVICE auto
eval(Ts&&... args) const -> decltype(thrust::get<Pos>(thrust::tuple<Ts...>{THRUST_FWD(args)...}))
eval(Ts&&... args) const -> decltype(thrust::get<Pos>(thrust::tuple<Ts&&...>{THRUST_FWD(args)...}))
{
return thrust::get<Pos>(thrust::tuple<Ts...>{THRUST_FWD(args)...});
return thrust::get<Pos>(thrust::tuple<Ts&&...>{THRUST_FWD(args)...});
}
};

Expand Down

0 comments on commit 9d4c3a8

Please sign in to comment.