Skip to content
7 changes: 7 additions & 0 deletions sycl/include/sycl/functional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ template <typename T = void> using bit_xor = std::bit_xor<T>;

// std:logical_and/std::logical_or with a non-void type returns bool,
// sycl requires returning T.
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
template <typename T = void> struct logical_and : std::logical_and<T> {};
template <typename T = void> struct logical_or : std::logical_or<T> {};

#else
template <typename T = void> struct logical_and {
T operator()(const T &lhs, const T &rhs) const { return lhs && rhs; }
};
Expand All @@ -35,6 +40,8 @@ template <typename T = void> struct logical_or {

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

#endif

// sycl::minimum definition should be consistent with std::min
template <typename T = void> struct minimum {
T operator()(const T &lhs, const T &rhs) const {
Expand Down
25 changes: 25 additions & 0 deletions sycl/test/basic_tests/logical_operations.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %clang -fpreview-breaking-changes -fsycl -fsyntax-only %s
// RUN: %clang -fsycl -fsyntax-only %s

#include <cassert>
#include <sycl/functional.hpp>
#include <type_traits>

int main() {
const auto logicalAnd = sycl::logical_and<int>();
const auto logicalOr = sycl::logical_or<int>();
const auto logicalAndVoid = sycl::logical_and<void>();
const auto logicalOrVoid = sycl::logical_or<void>();
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
static_assert(std::is_same_v<decltype(logicalAnd(1, 2)), bool>);
static_assert(std::is_same_v<decltype(logicalOr(1, 2)), bool>);
static_assert(std::is_same_v<decltype(logicalAndVoid(1, 2)), bool>);
static_assert(std::is_same_v<decltype(logicalOrVoid(1, 2)), bool>);
#else
static_assert(std::is_same_v<decltype(logicalAnd(1, 2)), int>);
static_assert(std::is_same_v<decltype(logicalOr(1, 2)), int>);
static_assert(std::is_same_v<decltype(logicalAndVoid(1, 2)), bool>);
static_assert(std::is_same_v<decltype(logicalOrVoid(1, 2)), bool>);
#endif
return 0;
}