Skip to content

Commit 885b14e

Browse files
[SYCL] Enforce DataT restrictions in marray/vec (#15662)
1 parent 2c7d9ff commit 885b14e

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

sycl/include/sycl/detail/type_traits.hpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -504,19 +504,9 @@ struct map_type<T, From, To, Rest...> {
504504
using type = std::conditional_t<std::is_same_v<From, T>, To,
505505
typename map_type<T, Rest...>::type>;
506506
};
507-
template <typename T, typename... Ts> constexpr bool CheckTypeIn() {
508-
constexpr bool SameType[] = {
509-
std::is_same_v<std::remove_cv_t<T>, std::remove_cv_t<Ts>>...};
510-
// Replace with std::any_of with C++20.
511-
for (size_t I = 0; I < sizeof...(Ts); ++I)
512-
if (SameType[I])
513-
return true;
514-
return false;
515-
}
516507

517-
// NOTE: We need a constexpr variable definition for the constexpr functions
518-
// as MSVC thinks function definitions are the same otherwise.
519-
template <typename... Ts> constexpr bool check_type_in_v = CheckTypeIn<Ts...>();
508+
template <typename T, typename... Ts>
509+
constexpr bool check_type_in_v = ((std::is_same_v<T, Ts> || ...));
520510

521511
} // namespace detail
522512
} // namespace _V1

sycl/include/sycl/marray.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ template <typename T, typename... Ts> struct GetMArrayArgsSize<T, Ts...> {
4848
/// \ingroup sycl_api
4949
template <typename Type, std::size_t NumElements> class marray {
5050
using DataT = Type;
51+
static_assert(std::is_same_v<DataT, std::remove_cv_t<DataT>> &&
52+
std::is_default_constructible_v<DataT> &&
53+
std::is_copy_constructible_v<DataT> &&
54+
std::is_copy_assignable_v<DataT> &&
55+
std::is_destructible_v<DataT>,
56+
"DataT must be a NumericType");
5157

5258
public:
5359
using value_type = Type;

sycl/include/sycl/vector.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class __SYCL_EBO vec
131131
: public detail::vec_arith<DataT, NumElements>,
132132
public detail::ScalarConversionOperatorMixIn<vec<DataT, NumElements>,
133133
DataT, NumElements> {
134+
static_assert(std::is_same_v<DataT, std::remove_cv_t<DataT>>,
135+
"DataT must be cv-unqualified");
134136

135137
static_assert(NumElements == 1 || NumElements == 2 || NumElements == 3 ||
136138
NumElements == 4 || NumElements == 8 || NumElements == 16,

sycl/test/basic_tests/marray/marray.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ template <size_t N> bool AllTrue(sycl::marray<bool, N> M) {
3838
AllTrue((LHS OP RHS[0]) == (LHS OP RHS)) && \
3939
AllTrue((LHS[0] OP RHS[0]) == (LHS OP RHS)));
4040

41-
struct NotDefaultConstructible {
42-
NotDefaultConstructible() = delete;
43-
constexpr NotDefaultConstructible(int){};
44-
};
45-
4641
template <typename T> void CheckBinOps() {
4742
sycl::marray<T, 3> ref_arr0{T(0)};
4843
sycl::marray<T, 3> ref_arr1{T(1)};
@@ -223,7 +218,6 @@ int main() {
223218
CheckConstexprVariadicCtors<sycl::half>();
224219
CheckConstexprVariadicCtors<float>();
225220
CheckConstexprVariadicCtors<double>();
226-
CheckConstexprVariadicCtors<NotDefaultConstructible>();
227221

228222
// check trivially copyability
229223
struct Copyable {

0 commit comments

Comments
 (0)