Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions libcudacxx/include/cuda/__utility/__basic_any/basic_any_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,25 @@ struct _CCCL_TYPE_VISIBILITY_DEFAULT __basic_any : __basic_any_base<_Interface>
//! `__icopyable<>`.
//! @post `has_value() == __other.has_value()`.
_CCCL_TEMPLATE(class _OtherInterface)
_CCCL_REQUIRES((!::cuda::std::same_as<_OtherInterface, _Interface>)
_CCCL_AND __any_convertible_to<__basic_any<_OtherInterface> const&, __basic_any>)
_CCCL_REQUIRES(
(!::cuda::std::same_as<_OtherInterface&, _Interface&>)
_CCCL_AND __any_convertible_to<__basic_any<_OtherInterface> const&, __basic_any>)
_CCCL_API __basic_any(__basic_any<_OtherInterface> const& __other)
{
__convert_from(__other);
}

//! @brief Non-template converting constructor from the corresponding
//! reference type `__basic_any<_Interface&>`. This enables implicit
//! conversion from proxy types (e.g. Cython's __Pyx_FakeReference)
//! that wrap a `__basic_any<_Interface&>` and provide
//! `operator __basic_any<_Interface&>&()`, since non-template parameters
//! participate in implicit conversion sequences.
_CCCL_API __basic_any(__basic_any<_Interface&> const& __other)
{
__convert_from(__other);
}
Comment on lines +171 to +180
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, please also add the corresponding move constructor and test for rvalue proxy


#if _CCCL_COMPILER(CLANG, <, 12) || _CCCL_COMPILER(GCC, <, 11)
// Older versions of clang and gcc need help disambiguating between
// __basic_any<__ireference<I>> and __basic_any<I&>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,61 @@ TEST_CASE("regression test for NVIDIA/cccl#8037", "[container][resource]")
{
STATIC_REQUIRE(cuda::std::move_constructible<my_resource_wrapper>);
}

// Minimal proxy that wraps a value and provides operator T&(), mimicking
// Cython's __Pyx_FakeReference<T> which wraps intermediate expression results.
template <typename T>
struct value_proxy
{
T value;

template <typename... Args>
explicit value_proxy(Args&&... args)
: value(std::forward<Args>(args)...)
{}

operator T&()
{
return value;
}
};

// See https://github.com/NVIDIA/cccl/issues/8316
TEST_CASE("any_resource from proxy-wrapped resource_ref", "[container][resource]")
{
host_device_resource mr;
cuda::mr::resource_ref<cuda::mr::host_accessible> ref{mr};

SECTION("direct construction from resource_ref")
{
cuda::mr::any_resource<cuda::mr::host_accessible> any{ref};
CHECK(any == ref);
}

SECTION("construction from proxy-wrapped resource_ref")
{
value_proxy<cuda::mr::resource_ref<cuda::mr::host_accessible>> proxy{mr};
cuda::mr::any_resource<cuda::mr::host_accessible> any{proxy};
CHECK(any == ref);
}
}

TEST_CASE("any_synchronous_resource from proxy-wrapped synchronous_resource_ref", "[container][resource]")
{
host_device_resource mr;
cuda::mr::synchronous_resource_ref<cuda::mr::host_accessible> ref{mr};

SECTION("direct construction from synchronous_resource_ref")
{
cuda::mr::any_synchronous_resource<cuda::mr::host_accessible> any{ref};
CHECK(any == ref);
}

SECTION("construction from proxy-wrapped synchronous_resource_ref")
{
value_proxy<cuda::mr::synchronous_resource_ref<cuda::mr::host_accessible>> proxy{mr};
cuda::mr::any_synchronous_resource<cuda::mr::host_accessible> any{proxy};
CHECK(any == ref);
}
}
#endif // __CUDA_ARCH__
Loading