Skip to content

Commit 6079db2

Browse files
[SYCL] logical operation return type is boolean (#17239)
fix to return boolean value type of `logical_and`/`logical_or` according to KhronosGroup/SYCL-Docs#648 CTS changes will be done in a separate PR --------- Co-authored-by: Steffen Larsen <steffen.larsen@intel.com>
1 parent 9ae8e2f commit 6079db2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

sycl/include/sycl/functional.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ template <typename T = void> using bit_xor = std::bit_xor<T>;
2323

2424
// std:logical_and/std::logical_or with a non-void type returns bool,
2525
// sycl requires returning T.
26+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
27+
template <typename T = void> struct logical_and : std::logical_and<T> {};
28+
template <typename T = void> struct logical_or : std::logical_or<T> {};
29+
30+
#else
2631
template <typename T = void> struct logical_and {
2732
T operator()(const T &lhs, const T &rhs) const { return lhs && rhs; }
2833
};
@@ -35,6 +40,8 @@ template <typename T = void> struct logical_or {
3540

3641
template <> struct logical_or<void> : std::logical_or<void> {};
3742

43+
#endif
44+
3845
// sycl::minimum definition should be consistent with std::min
3946
template <typename T = void> struct minimum {
4047
T operator()(const T &lhs, const T &rhs) const {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %clang -fpreview-breaking-changes -fsycl -fsyntax-only %s
2+
// RUN: %clang -fsycl -fsyntax-only %s
3+
4+
#include <cassert>
5+
#include <sycl/functional.hpp>
6+
#include <type_traits>
7+
8+
int main() {
9+
const auto logicalAnd = sycl::logical_and<int>();
10+
const auto logicalOr = sycl::logical_or<int>();
11+
const auto logicalAndVoid = sycl::logical_and<void>();
12+
const auto logicalOrVoid = sycl::logical_or<void>();
13+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
14+
static_assert(std::is_same_v<decltype(logicalAnd(1, 2)), bool>);
15+
static_assert(std::is_same_v<decltype(logicalOr(1, 2)), bool>);
16+
static_assert(std::is_same_v<decltype(logicalAndVoid(1, 2)), bool>);
17+
static_assert(std::is_same_v<decltype(logicalOrVoid(1, 2)), bool>);
18+
#else
19+
static_assert(std::is_same_v<decltype(logicalAnd(1, 2)), int>);
20+
static_assert(std::is_same_v<decltype(logicalOr(1, 2)), int>);
21+
static_assert(std::is_same_v<decltype(logicalAndVoid(1, 2)), bool>);
22+
static_assert(std::is_same_v<decltype(logicalOrVoid(1, 2)), bool>);
23+
#endif
24+
return 0;
25+
}

0 commit comments

Comments
 (0)