Skip to content

Commit 67c6589

Browse files
authored
Merge pull request #15 from KernelTuner/fix-cxx20-alias-deduction-guides
Remove deduction guides for alias templates to support C++20
2 parents 5226c92 + 1d03298 commit 67c6589

5 files changed

Lines changed: 53 additions & 54 deletions

File tree

‎include/kernel_float/memory.h‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,14 +1090,6 @@ vector_ptr(T*) -> vector_ptr<T, 1, access_policy<T>>;
10901090

10911091
template<typename T>
10921092
vector_ptr(const T*) -> vector_ptr<T, 1, access_policy<const T>>;
1093-
1094-
#if __cpp_deduction_guides >= 201907L
1095-
template<typename T>
1096-
vec_ptr(T*) -> vec_ptr<T, 1>;
1097-
1098-
template<typename T>
1099-
vec_ptr(const T*) -> vec_ptr<T, 1, const T>;
1100-
#endif
11011093
#endif
11021094

11031095
} // namespace kernel_float

‎include/kernel_float/prelude.h‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,6 @@ static constexpr kconstant<long long int> operator""_c(unsigned long long int v)
108108
return static_cast<long long int>(v);
109109
}
110110

111-
// Deduction guides for aliases are only supported from C++20
112-
#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201907L
113-
template<typename T>
114-
kscalar(T&&) -> kscalar<decay_t<T>>;
115-
116-
template<typename... Args>
117-
kvec(Args&&...) -> kvec<promote_t<Args...>, sizeof...(Args)>;
118-
119-
template<typename T>
120-
kconstant(T&&) -> kconstant<decay_t<T>>;
121-
#endif
122-
123111
} // namespace prelude
124112
} // namespace kernel_float
125113

‎include/kernel_float/vector.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,6 @@ KERNEL_FLOAT_INLINE vec<promote_t<Args...>, sizeof...(Args)> make_vec(Args&&...
380380
// Deduction guide for `vector`
381381
template<typename... Args>
382382
vector(Args&&... args) -> vector<promote_t<Args...>, extent<sizeof...(Args)>>;
383-
384-
// Deduction guides for aliases are only supported from C++20
385-
#if __cpp_deduction_guides >= 201907L
386-
template<typename... Args>
387-
vec(Args&&... args) -> vec<promote_t<Args...>, sizeof...(Args)>;
388-
#endif
389383
#endif
390384

391385
} // namespace kernel_float

‎single_include/kernel_float.h‎

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
//================================================================================
1818
// this file has been auto-generated, do not modify its contents!
19-
// date: 2026-08-28 13:42:54.102829
20-
// git hash: 14a94fbc188ca3285e7351e5bb79184ce89c75d7
19+
// date: 2026-09-25 19:45:19.408615
20+
// git hash: 5226c9232b45c090be46c41e17034c089ffbf8d0
2121
//================================================================================
2222

2323
#ifndef KERNEL_FLOAT_MACROS_H
@@ -3710,14 +3710,6 @@ vector_ptr(T*) -> vector_ptr<T, 1, access_policy<T>>;
37103710

37113711
template<typename T>
37123712
vector_ptr(const T*) -> vector_ptr<T, 1, access_policy<const T>>;
3713-
3714-
#if __cpp_deduction_guides >= 201907L
3715-
template<typename T>
3716-
vec_ptr(T*) -> vec_ptr<T, 1>;
3717-
3718-
template<typename T>
3719-
vec_ptr(const T*) -> vec_ptr<T, 1, const T>;
3720-
#endif
37213713
#endif
37223714

37233715
} // namespace kernel_float
@@ -4571,12 +4563,6 @@ KERNEL_FLOAT_INLINE vec<promote_t<Args...>, sizeof...(Args)> make_vec(Args&&...
45714563
// Deduction guide for `vector`
45724564
template<typename... Args>
45734565
vector(Args&&... args) -> vector<promote_t<Args...>, extent<sizeof...(Args)>>;
4574-
4575-
// Deduction guides for aliases are only supported from C++20
4576-
#if __cpp_deduction_guides >= 201907L
4577-
template<typename... Args>
4578-
vec(Args&&... args) -> vec<promote_t<Args...>, sizeof...(Args)>;
4579-
#endif
45804566
#endif
45814567

45824568
} // namespace kernel_float
@@ -5788,18 +5774,6 @@ static constexpr kconstant<long long int> operator""_c(unsigned long long int v)
57885774
return static_cast<long long int>(v);
57895775
}
57905776

5791-
// Deduction guides for aliases are only supported from C++20
5792-
#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201907L
5793-
template<typename T>
5794-
kscalar(T&&) -> kscalar<decay_t<T>>;
5795-
5796-
template<typename... Args>
5797-
kvec(Args&&...) -> kvec<promote_t<Args...>, sizeof...(Args)>;
5798-
5799-
template<typename T>
5800-
kconstant(T&&) -> kconstant<decay_t<T>>;
5801-
#endif
5802-
58035777
} // namespace prelude
58045778
} // namespace kernel_float
58055779

‎tests/deduction.cu‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <type_traits>
2+
3+
#include "common.h"
4+
#include "kernel_float/prelude.h"
5+
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).
10+
11+
namespace deduction_tests {
12+
using namespace kernel_float::prelude;
13+
14+
struct packed3 {
15+
float x, y, z; // sizeof(packed3) != alignof(packed3)
16+
};
17+
18+
TEST_CASE("deduction guides") {
19+
float* fp = nullptr;
20+
const packed3* cp = nullptr;
21+
22+
kf::vector v(1, 2.0f);
23+
STATIC_REQUIRE(std::is_same_v<decltype(v), kf::vec<float, 2>>);
24+
25+
kf::vector_ptr p(fp);
26+
STATIC_REQUIRE(std::is_same_v<decltype(p), kf::vector_ptr<float, 1, kf::access_policy<float>>>);
27+
28+
kf::vector_ptr q(cp);
29+
STATIC_REQUIRE(
30+
std::is_same_v<decltype(q), kf::vector_ptr<packed3, 1, kf::access_policy<const packed3>>>);
31+
32+
kf::constant c(2.0);
33+
STATIC_REQUIRE(std::is_same_v<decltype(c), kf::constant<double>>);
34+
CHECK(c.get() == 2.0);
35+
}
36+
37+
// From C++20, the compiler derives deduction guides for alias templates from those of the class
38+
// template they name.
39+
#if __cplusplus >= 202002L
40+
TEST_CASE("deduction guides for alias templates") {
41+
kf::scalar s(1.5);
42+
STATIC_REQUIRE(std::is_same_v<decltype(s), kf::scalar<double>>);
43+
44+
kscalar ks(1.5f);
45+
STATIC_REQUIRE(std::is_same_v<decltype(ks), kscalar<float>>);
46+
47+
kconstant kc(2.0);
48+
STATIC_REQUIRE(std::is_same_v<decltype(kc), kconstant<double>>);
49+
}
50+
#endif
51+
} // namespace deduction_tests

0 commit comments

Comments
 (0)