From c94939e0ec40ece9dc355d8ecec02a1ba74bec24 Mon Sep 17 00:00:00 2001 From: David Bayer Date: Mon, 18 Nov 2024 13:24:06 +0100 Subject: [PATCH 1/9] backport `to_underlying` to C++11 --- libcudacxx/include/cuda/std/__utility/to_underlying.h | 10 +--------- libcudacxx/include/cuda/std/version | 5 +++-- .../utility/utility.underlying/to_underlying.pass.cpp | 4 +--- .../utility.underlying/to_underlying.verify.cpp | 4 +--- 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/libcudacxx/include/cuda/std/__utility/to_underlying.h b/libcudacxx/include/cuda/std/__utility/to_underlying.h index 2c01461c0a9..6ab88bf0020 100644 --- a/libcudacxx/include/cuda/std/__utility/to_underlying.h +++ b/libcudacxx/include/cuda/std/__utility/to_underlying.h @@ -25,19 +25,11 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD -template -_LIBCUDACXX_HIDE_FROM_ABI constexpr typename underlying_type<_Tp>::type __to_underlying(_Tp __val) noexcept -{ - return static_cast::type>(__val); -} - -#if _CCCL_STD_VER > 2020 template _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr underlying_type_t<_Tp> to_underlying(_Tp __val) noexcept { - return _CUDA_VSTD::__to_underlying(__val); + return static_cast>(__val); } -#endif _LIBCUDACXX_END_NAMESPACE_STD diff --git a/libcudacxx/include/cuda/std/version b/libcudacxx/include/cuda/std/version index c2724358e9f..059bfcccc66 100644 --- a/libcudacxx/include/cuda/std/version +++ b/libcudacxx/include/cuda/std/version @@ -29,6 +29,8 @@ # include // otherwise go for the smallest possible header #endif // !_CCCL_COMPILER(NVRTC) +#define __cccl_lib_to_underlying 202102L + #if _CCCL_STD_VER >= 2014 # define __cccl_lib_bit_cast 201806L # define __cccl_lib_chrono_udls 201304L @@ -244,8 +246,7 @@ // # define __cccl_lib_stdatomic_h 202011L // # define __cccl_lib_string_contains 202011L // # define __cccl_lib_string_resize_and_overwrite 202110L -# define __cccl_lib_to_underlying 202102L -# define __cccl_lib_unreachable 202202L +# define __cccl_lib_unreachable 202202L #endif // _CCCL_STD_VER >= 2023 diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp index 7a68ac6444a..67dd4abe278 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp @@ -7,11 +7,9 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 - // [utility.underlying], to_underlying // template -// constexpr underlying_type_t to_underlying( T value ) noexcept; // C++2b +// constexpr underlying_type_t to_underlying( T value ) noexcept; #include #include diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.verify.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.verify.cpp index 04fc27cd4ce..ad3c9b030f9 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.verify.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.verify.cpp @@ -7,11 +7,9 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 - // [utility.underlying], to_underlying // template -// constexpr underlying_type_t to_underlying( T value ) noexcept; // C++2b +// constexpr underlying_type_t to_underlying( T value ) noexcept; #include From 963d8813359081595d0c15580dcfa8864e979313 Mon Sep 17 00:00:00 2001 From: David Bayer Date: Mon, 18 Nov 2024 14:46:16 +0100 Subject: [PATCH 2/9] omit C++11 in pass tests --- .../utilities/utility/utility.underlying/to_underlying.pass.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp index 67dd4abe278..10dfccbc625 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++11 + // [utility.underlying], to_underlying // template // constexpr underlying_type_t to_underlying( T value ) noexcept; From e8d679dcea3dccaec9e1b1afac41b2854cca5476 Mon Sep 17 00:00:00 2001 From: David Bayer Date: Mon, 18 Nov 2024 15:41:18 +0100 Subject: [PATCH 3/9] fix test compilation for c++11 --- .../utility/utility.underlying/to_underlying.pass.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp index 10dfccbc625..b1993487e89 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp @@ -7,8 +7,6 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++11 - // [utility.underlying], to_underlying // template // constexpr underlying_type_t to_underlying( T value ) noexcept; @@ -61,7 +59,7 @@ struct WithBitfieldEnums e_bool e3 : 1; }; -__host__ __device__ constexpr bool test() +__host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { ASSERT_NOEXCEPT(cuda::std::to_underlying(e_default::a)); ASSERT_SAME_TYPE(int, decltype(cuda::std::to_underlying(e_default::a))); @@ -102,7 +100,10 @@ __host__ __device__ constexpr bool test() int main(int, char**) { test(); - static_assert(test()); + +#if TEST_STD_VER >= 14 + static_assert(test(), ""); +#endif return 0; } From 51cd06a4b974423abdccaa7aab56f0806107e782 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Mon, 18 Nov 2024 15:53:19 +0100 Subject: [PATCH 4/9] Update libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp --- .../utilities/utility/utility.underlying/to_underlying.pass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp index b1993487e89..a2d3f1b3b01 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp @@ -103,7 +103,7 @@ int main(int, char**) #if TEST_STD_VER >= 14 static_assert(test(), ""); -#endif +#endif // TEST_STD_VER >= 14 return 0; } From 19c197b85e0465f8731a401ef9a7ce5d97c6cc17 Mon Sep 17 00:00:00 2001 From: David Bayer Date: Mon, 18 Nov 2024 16:02:16 +0100 Subject: [PATCH 5/9] remove remains of `__to_underlying` --- c2h/include/c2h/catch2_test_helper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c2h/include/c2h/catch2_test_helper.h b/c2h/include/c2h/catch2_test_helper.h index 9357cba8ac1..729c1f43ebd 100644 --- a/c2h/include/c2h/catch2_test_helper.h +++ b/c2h/include/c2h/catch2_test_helper.h @@ -221,7 +221,7 @@ struct Catch::StringMaker { static auto convert(cudaError e) -> std::string { - return std::to_string(cuda::std::__to_underlying(e)) + " (" + cudaGetErrorString(e) + ")"; + return std::to_string(cuda::std::to_underlying(e)) + " (" + cudaGetErrorString(e) + ")"; } }; From 95f6048b9c0021e46d481872f5da31969e7c7633 Mon Sep 17 00:00:00 2001 From: David Bayer Date: Mon, 18 Nov 2024 16:32:22 +0100 Subject: [PATCH 6/9] fix invalid test c++ standard comparison --- .../utility/utility.underlying/to_underlying.pass.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp index a2d3f1b3b01..40a62ac7796 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp @@ -101,9 +101,9 @@ int main(int, char**) { test(); -#if TEST_STD_VER >= 14 +#if TEST_STD_VER >= 2014 static_assert(test(), ""); -#endif // TEST_STD_VER >= 14 +#endif // TEST_STD_VER >= 2014 return 0; } From effc1ff701f33defadd580166e75583a319637ad Mon Sep 17 00:00:00 2001 From: David Bayer Date: Mon, 18 Nov 2024 17:54:26 +0100 Subject: [PATCH 7/9] fix constexpr initialization in pass test --- .../utilities/utility/utility.underlying/to_underlying.pass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp index 40a62ac7796..051780a8b2e 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp @@ -86,7 +86,7 @@ __host__ __device__ TEST_CONSTEXPR_CXX14 bool test() assert(cuda::std::numeric_limits::min() == cuda::std::to_underlying(enum_min)); assert(cuda::std::numeric_limits::max() == cuda::std::to_underlying(enum_max)); - WithBitfieldEnums bf; + WithBitfieldEnums bf{}; bf.e1 = static_cast(3); bf.e2 = e_ushort::e; bf.e3 = e_bool::t; From f1b964060761c2f61ac13d5eccd77fb0746a5a39 Mon Sep 17 00:00:00 2001 From: David Bayer Date: Mon, 18 Nov 2024 21:59:27 +0100 Subject: [PATCH 8/9] disable test on bit field enums for pre gcc 9.3 due to unmuteable warnings --- .../utility/utility.underlying/to_underlying.pass.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp index 051780a8b2e..628bfcf5d68 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp @@ -52,12 +52,14 @@ enum class e_bool : cuda::std::uint8_t t = 1 }; +#if !defined(TEST_COMPILER_GCC) || TEST_GCC_VER >= 903 struct WithBitfieldEnums { e_default e1 : 3; e_ushort e2 : 6; e_bool e3 : 1; }; +#endif // !defined(TEST_COMPILER_GCC) || TEST_GCC_VER >= 903 __host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { @@ -86,6 +88,7 @@ __host__ __device__ TEST_CONSTEXPR_CXX14 bool test() assert(cuda::std::numeric_limits::min() == cuda::std::to_underlying(enum_min)); assert(cuda::std::numeric_limits::max() == cuda::std::to_underlying(enum_max)); +#if !defined(TEST_COMPILER_GCC) || TEST_GCC_VER >= 903 WithBitfieldEnums bf{}; bf.e1 = static_cast(3); bf.e2 = e_ushort::e; @@ -93,6 +96,7 @@ __host__ __device__ TEST_CONSTEXPR_CXX14 bool test() assert(3 == cuda::std::to_underlying(bf.e1)); assert(25 == cuda::std::to_underlying(bf.e2)); assert(1 == cuda::std::to_underlying(bf.e3)); +#endif // !defined(TEST_COMPILER_GCC) || TEST_GCC_VER >= 903 return true; } From 2ade9a8123057babc58cc3b83932f76de2526557 Mon Sep 17 00:00:00 2001 From: David Bayer Date: Tue, 19 Nov 2024 09:30:12 +0100 Subject: [PATCH 9/9] be more specific with gcc versions when omiting bit field tests --- .../utility.underlying/to_underlying.pass.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp index 628bfcf5d68..011eb3aaccf 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.underlying/to_underlying.pass.cpp @@ -18,6 +18,10 @@ #include "test_macros.h" +#if defined(TEST_COMPILER_GCC) && ((TEST_GCC_VER >= 900 && TEST_GCC_VER < 903) || TEST_GCC_VER < 804) +# define OMIT_BITFIELD_ENUMS 1 +#endif + enum class e_default { a = 0, @@ -52,14 +56,14 @@ enum class e_bool : cuda::std::uint8_t t = 1 }; -#if !defined(TEST_COMPILER_GCC) || TEST_GCC_VER >= 903 +#if !OMIT_BITFIELD_ENUMS struct WithBitfieldEnums { e_default e1 : 3; e_ushort e2 : 6; e_bool e3 : 1; }; -#endif // !defined(TEST_COMPILER_GCC) || TEST_GCC_VER >= 903 +#endif // !OMIT_BITFIELD_ENUMS __host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { @@ -88,7 +92,7 @@ __host__ __device__ TEST_CONSTEXPR_CXX14 bool test() assert(cuda::std::numeric_limits::min() == cuda::std::to_underlying(enum_min)); assert(cuda::std::numeric_limits::max() == cuda::std::to_underlying(enum_max)); -#if !defined(TEST_COMPILER_GCC) || TEST_GCC_VER >= 903 +#if !OMIT_BITFIELD_ENUMS WithBitfieldEnums bf{}; bf.e1 = static_cast(3); bf.e2 = e_ushort::e; @@ -96,7 +100,7 @@ __host__ __device__ TEST_CONSTEXPR_CXX14 bool test() assert(3 == cuda::std::to_underlying(bf.e1)); assert(25 == cuda::std::to_underlying(bf.e2)); assert(1 == cuda::std::to_underlying(bf.e3)); -#endif // !defined(TEST_COMPILER_GCC) || TEST_GCC_VER >= 903 +#endif // !OMIT_BITFIELD_ENUMS return true; }