Skip to content

Commit 97e32b3

Browse files
committed
Fix GCC < 11 and NVRTC build failures
- resource_cast: explicitly static_cast to __basic_any base before calling __any_cast, working around GCC < 11 inability to deduce template arguments from derived-to-base class conversions. - basic_any test: change test_iset_dynamic_cast from _CCCL_HOST to _CCCL_HOST_DEVICE so NVRTC can compile the file.
1 parent 51613b3 commit 97e32b3

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

libcudacxx/include/cuda/__memory_resource/any_resource.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,8 @@ template <class _Tp, class... _Properties>
993993
{
994994
static_assert(::cuda::std::is_void_v<_Tp> || ::cuda::mr::resource_with<_Tp, _Properties...>,
995995
"_Tp must be void or satisfy resource_with<_Tp, _Properties...>");
996-
return ::cuda::__any_cast<_Tp>(__res);
996+
// Use static_cast to the __basic_any base to work around GCC < 11 template argument deduction issues.
997+
return ::cuda::__any_cast<_Tp>(static_cast<::cuda::__basic_any<__iasync_resource<_Properties...>>*>(__res));
997998
}
998999

9991000
//! @overload
@@ -1002,7 +1003,7 @@ template <class _Tp, class... _Properties>
10021003
{
10031004
static_assert(::cuda::std::is_void_v<_Tp> || ::cuda::mr::resource_with<_Tp, _Properties...>,
10041005
"_Tp must be void or satisfy resource_with<_Tp, _Properties...>");
1005-
return ::cuda::__any_cast<_Tp>(__res);
1006+
return ::cuda::__any_cast<_Tp>(static_cast<const ::cuda::__basic_any<__iasync_resource<_Properties...>>*>(__res));
10061007
}
10071008

10081009
//! @overload
@@ -1011,7 +1012,7 @@ template <class _Tp, class... _Properties>
10111012
{
10121013
static_assert(::cuda::std::is_void_v<_Tp> || ::cuda::mr::synchronous_resource_with<_Tp, _Properties...>,
10131014
"_Tp must be void or satisfy synchronous_resource_with<_Tp, _Properties...>");
1014-
return ::cuda::__any_cast<_Tp>(__res);
1015+
return ::cuda::__any_cast<_Tp>(static_cast<::cuda::__basic_any<__iresource<_Properties...>>*>(__res));
10151016
}
10161017

10171018
//! @overload
@@ -1021,7 +1022,7 @@ template <class _Tp, class... _Properties>
10211022
{
10221023
static_assert(::cuda::std::is_void_v<_Tp> || ::cuda::mr::synchronous_resource_with<_Tp, _Properties...>,
10231024
"_Tp must be void or satisfy synchronous_resource_with<_Tp, _Properties...>");
1024-
return ::cuda::__any_cast<_Tp>(__res);
1025+
return ::cuda::__any_cast<_Tp>(static_cast<const ::cuda::__basic_any<__iresource<_Properties...>>*>(__res));
10251026
}
10261027

10271028
//! @overload
@@ -1030,7 +1031,7 @@ template <class _Tp, class... _Properties>
10301031
{
10311032
static_assert(::cuda::std::is_void_v<_Tp> || ::cuda::mr::resource_with<_Tp, _Properties...>,
10321033
"_Tp must be void or satisfy resource_with<_Tp, _Properties...>");
1033-
return ::cuda::__any_cast<_Tp>(__res);
1034+
return ::cuda::__any_cast<_Tp>(static_cast<::cuda::__basic_any<__iasync_resource<_Properties...>&>*>(__res));
10341035
}
10351036

10361037
//! @overload
@@ -1039,7 +1040,7 @@ template <class _Tp, class... _Properties>
10391040
{
10401041
static_assert(::cuda::std::is_void_v<_Tp> || ::cuda::mr::resource_with<_Tp, _Properties...>,
10411042
"_Tp must be void or satisfy resource_with<_Tp, _Properties...>");
1042-
return ::cuda::__any_cast<_Tp>(__res);
1043+
return ::cuda::__any_cast<_Tp>(static_cast<const ::cuda::__basic_any<__iasync_resource<_Properties...>&>*>(__res));
10431044
}
10441045

10451046
//! @overload
@@ -1048,7 +1049,7 @@ template <class _Tp, class... _Properties>
10481049
{
10491050
static_assert(::cuda::std::is_void_v<_Tp> || ::cuda::mr::synchronous_resource_with<_Tp, _Properties...>,
10501051
"_Tp must be void or satisfy synchronous_resource_with<_Tp, _Properties...>");
1051-
return ::cuda::__any_cast<_Tp>(__res);
1052+
return ::cuda::__any_cast<_Tp>(static_cast<::cuda::__basic_any<__iresource<_Properties...>&>*>(__res));
10521053
}
10531054

10541055
//! @overload
@@ -1058,7 +1059,7 @@ template <class _Tp, class... _Properties>
10581059
{
10591060
static_assert(::cuda::std::is_void_v<_Tp> || ::cuda::mr::synchronous_resource_with<_Tp, _Properties...>,
10601061
"_Tp must be void or satisfy synchronous_resource_with<_Tp, _Properties...>");
1061-
return ::cuda::__any_cast<_Tp>(__res);
1062+
return ::cuda::__any_cast<_Tp>(static_cast<const ::cuda::__basic_any<__iresource<_Properties...>&>*>(__res));
10621063
}
10631064

10641065
// ── dynamic_resource_cast ───────────────────────────────────────────────────

libcudacxx/test/libcudacxx/cuda/utility/basic_any.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ struct HasBoth
675675
int val;
676676
};
677677

678-
_CCCL_HOST void test_iset_dynamic_cast()
678+
_CCCL_HOST_DEVICE void test_iset_dynamic_cast()
679679
{
680680
// Start with both interfaces, narrow to one, verify cross-cast to the other fails
681681
cuda::__basic_any<iset_ab> ab{::cuda::std::in_place_type<HasBoth>, 7};

0 commit comments

Comments
 (0)