Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions sycl/include/sycl/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,13 @@ template <typename Self> class ConversionToVecMixin {

public:
operator vec_ty() const {
vec_ty res{*static_cast<const Self *>(this)};
return res;
auto &self = *static_cast<const Self *>(this);
if constexpr (vec_ty::size() == 1)
// Avoid recursion by explicitly going through `vec(const DataT &)` ctor.
return vec_ty{static_cast<typename vec_ty::element_type>(self)};
else
// Uses `vec`'s variadic ctor.
return vec_ty{self};
}
};

Expand Down Expand Up @@ -398,9 +403,8 @@ class __SYCL_EBO Swizzle
public ApplyIf<sizeof...(Indexes) == 1,
ScalarConversionOperatorsMixIn<
Swizzle<IsConstVec, DataT, VecSize, Indexes...>>>,
public ApplyIf<sizeof...(Indexes) != 1,
ConversionToVecMixin<
Swizzle<IsConstVec, DataT, VecSize, Indexes...>>>,
public ConversionToVecMixin<
Swizzle<IsConstVec, DataT, VecSize, Indexes...>>,
public NamedSwizzlesMixinBoth<
Swizzle<IsConstVec, DataT, VecSize, Indexes...>> {
using Base = SwizzleBase<Swizzle<IsConstVec, DataT, VecSize, Indexes...>>;
Expand Down
4 changes: 2 additions & 2 deletions sycl/test/basic_tests/vectors/cxx_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ using sw_double_2 = decltype(std::declval<vec<double, 4>>().swizzle<1, 2>());
static_assert( std::is_invocable_v<decltype(f_half_v1), half>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_half_v1), float>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_half_v1), double>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_half_v1), sw_half_1>);
static_assert( std::is_invocable_v<decltype(f_half_v1), sw_half_1>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_half_v1), sw_float_1>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_half_v1), sw_double_1>);
static_assert( std::is_invocable_v<decltype(f_half_v1), vec<half, 1>>);
Expand All @@ -64,7 +64,7 @@ static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_float_v1), half>)
static_assert( std::is_invocable_v<decltype(f_float_v1), float>);
static_assert( std::is_invocable_v<decltype(f_float_v1), double>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_float_v1), sw_half_1>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_float_v1), sw_float_1>);
static_assert( std::is_invocable_v<decltype(f_float_v1), sw_float_1>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_float_v1), sw_double_1>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_float_v1), vec<half, 1>>);
static_assert( std::is_invocable_v<decltype(f_float_v1), vec<float, 1>>);
Expand Down