33#include " common.h"
44#include " kernel_float/prelude.h"
55
6- // Class template argument deduction. These checks are compile-time only: if this file compiles,
7- // they pass. The file is valid as both C++17 and C++20.
6+ // Class template argument deduction. These tests run on host only: a bug in clang (HIP)
7+ // treats deduction guides as host functions, so CTAD cannot be used in device code.
8+ // See https://github.com/llvm/llvm-project/issues/146646 (fixed in LLVM 22 by
9+ // https://github.com/llvm/llvm-project/pull/170481).
810
911namespace deduction_tests {
1012using namespace kernel_float ::prelude;
@@ -13,35 +15,37 @@ struct packed3 {
1315 float x, y, z; // sizeof(packed3) != alignof(packed3)
1416};
1517
16- __host__ __device__ void class_templates (float * fp, const packed3* cp) {
18+ TEST_CASE (" deduction guides" ) {
19+ float * fp = nullptr ;
20+ const packed3* cp = nullptr ;
21+
1722 kf::vector v (1 , 2 .0f );
18- static_assert (std::is_same <decltype (v), kf::vec<float , 2 >>::value, " " );
23+ STATIC_REQUIRE (std::is_same_v <decltype (v), kf::vec<float , 2 >>);
1924
2025 kf::vector_ptr p (fp);
21- static_assert (
22- std::is_same<decltype (p), kf::vector_ptr<float , 1 , kf::access_policy<float >>>::value,
23- " " );
26+ STATIC_REQUIRE (std::is_same_v<decltype (p), kf::vector_ptr<float , 1 , kf::access_policy<float >>>);
2427
2528 kf::vector_ptr q (cp);
26- using expected_q = kf::vector_ptr<packed3, 1 , kf::access_policy< const packed3>>;
27- static_assert ( std::is_same <decltype (q), expected_q>::value, " " );
29+ STATIC_REQUIRE (
30+ std::is_same_v <decltype (q), kf::vector_ptr<packed3, 1 , kf::access_policy< const packed3>>> );
2831
2932 kf::constant c (2.0 );
30- static_assert (std::is_same<decltype (c), kf::constant<double >>::value, " " );
33+ STATIC_REQUIRE (std::is_same_v<decltype (c), kf::constant<double >>);
34+ CHECK (c.get () == 2.0 );
3135}
3236
3337// From C++20, the compiler derives deduction guides for alias templates from those of the class
3438// template they name.
3539#if __cplusplus >= 202002L
36- __host__ __device__ void alias_templates ( ) {
40+ TEST_CASE ( " deduction guides for alias templates " ) {
3741 kf::scalar s (1.5 );
38- static_assert (std::is_same <decltype (s), kf::scalar<double >>::value, " " );
42+ STATIC_REQUIRE (std::is_same_v <decltype (s), kf::scalar<double >>);
3943
4044 kscalar ks (1 .5f );
41- static_assert (std::is_same <decltype (ks), kscalar<float >>::value, " " );
45+ STATIC_REQUIRE (std::is_same_v <decltype (ks), kscalar<float >>);
4246
4347 kconstant kc (2.0 );
44- static_assert (std::is_same <decltype (kc), kconstant<double >>::value, " " );
48+ STATIC_REQUIRE (std::is_same_v <decltype (kc), kconstant<double >>);
4549}
4650#endif
4751} // namespace deduction_tests
0 commit comments