Skip to content

Commit b6df1d9

Browse files
committed
[SYCL] update test to check void types
1 parent 48153fb commit b6df1d9

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

sycl/include/sycl/functional.hpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,34 @@ 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-
template <typename T = void> struct logical_and {
26+
template <typename T = void>
27+
struct logical_and
2728
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
28-
bool
29-
#else
30-
T
29+
: std::logical_and<T>
3130
#endif
32-
operator()(const T &lhs, const T &rhs) const {
33-
return lhs && rhs;
34-
}
35-
};
31+
{
32+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
33+
T operator()(const T &lhs, const T &rhs) const { return lhs && rhs; }
34+
#endif
35+
}; // namespace _V1
3636

37+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
3738
template <> struct logical_and<void> : std::logical_and<void> {};
39+
#endif
3840

39-
template <typename T = void> struct logical_or {
41+
template <typename T = void>
42+
struct logical_or
4043
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
41-
bool
42-
#else
43-
T
44+
: std::logical_or<T>
4445
#endif
45-
operator()(const T &lhs, const T &rhs) const {
46-
return lhs || rhs;
47-
}
48-
};
49-
46+
{
47+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
48+
T operator()(const T &lhs, const T &rhs) const { return lhs || rhs; }
49+
#endif
50+
}; // namespace sycl
51+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
5052
template <> struct logical_or<void> : std::logical_or<void> {};
53+
#endif
5154

5255
// sycl::minimum definition should be consistent with std::min
5356
template <typename T = void> struct minimum {

sycl/test/basic_tests/logical_operations.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// RUN: %clang -D__INTEL_PREVIEW_BREAKING_CHANGES -fsycl -o - %s
1+
// RUN: %clang -fpreview-breaking-changes -fsycl -o - %s
2+
// RUN: not %clang -fpreview-breaking-changes -fsycl -DTEST_VOID_TYPES -o - %s
23
// RUN: %clang -fsycl -o - %s
4+
// RUN: not %clang -fsycl -DTEST_VOID_TYPES -o - %s
35

46
#include <cassert>
57
#include <sycl/functional.hpp>
@@ -14,6 +16,20 @@ int main() {
1416
#else
1517
static_assert(std::is_same_v<decltype(logicalAnd(1, 2)), int> == true);
1618
static_assert(std::is_same_v<decltype(logicalOr(1, 2)), int> == true);
19+
#endif
20+
const auto logicalAndVoid = sycl::logical_and<void>();
21+
const auto logicalOrVoid = sycl::logical_or<void>();
22+
23+
static_assert(std::is_same_v<decltype(logicalAndVoid(1, 2)), bool> == true);
24+
static_assert(std::is_same_v<decltype(logicalOrVoid(1, 2)), bool> == true);
25+
26+
#ifdef TEST_VOID_TYPES
27+
static_assert(std::is_same_v<decltype(logicalAndVoid(static_cast<void>(1),
28+
static_cast<void>(2))),
29+
bool> == true);
30+
static_assert(std::is_same_v<decltype(logicalOrVoid(static_cast<void>(1),
31+
static_cast<void>(2))),
32+
bool> == true);
1733
#endif
1834
return 0;
1935
}

0 commit comments

Comments
 (0)