Skip to content

Commit 2249491

Browse files
authored
[SYCL] Add missing const to several operators of marray class (#2946)
Several unary operators were missing const in arguments. Signed-off-by: iburylov <[email protected]>
1 parent d7f1b53 commit 2249491

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

sycl/include/CL/sycl/marray.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,31 +276,31 @@ template <typename Type, std::size_t NumElements> class marray {
276276
// && dataT != cl_half
277277
template <typename T = DataT>
278278
friend typename std::enable_if<std::is_integral<T>::value, marray>::type
279-
operator~(marray &Lhs) {
279+
operator~(const marray &Lhs) {
280280
marray Ret;
281281
for (size_t I = 0; I < NumElements; ++I) {
282282
Ret[I] = ~Lhs[I];
283283
}
284284
return Ret;
285285
}
286286

287-
friend marray<bool, NumElements> operator!(marray &Lhs) {
287+
friend marray<bool, NumElements> operator!(const marray &Lhs) {
288288
marray<bool, NumElements> Ret;
289289
for (size_t I = 0; I < NumElements; ++I) {
290290
Ret[I] = !Lhs[I];
291291
}
292292
return Ret;
293293
}
294294

295-
friend marray operator+(marray &Lhs) {
295+
friend marray operator+(const marray &Lhs) {
296296
marray Ret;
297297
for (size_t I = 0; I < NumElements; ++I) {
298298
Ret[I] = +Lhs[I];
299299
}
300300
return Ret;
301301
}
302302

303-
friend marray operator-(marray &Lhs) {
303+
friend marray operator-(const marray &Lhs) {
304304
marray Ret;
305305
for (size_t I = 0; I < NumElements; ++I) {
306306
Ret[I] = -Lhs[I];

sycl/test/basic_tests/marray/marray.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,15 @@ int main() {
8383
b___ = t123 < 2;
8484
assert(b___[0] == true && b___[1] == false && b___[2] == false);
8585

86+
// test const operator forms
87+
t___ = -mint3{1, 2, 3};
88+
assert(t___[0] == -1 && t___[1] == -2 && t___[2] == -3);
89+
t___ = +mint3{1, 2, 3};
90+
assert(t___[0] == +1 && t___[1] == +2 && t___[2] == +3);
91+
t___ = ~mint3{1, 2, 3};
92+
assert(t___[0] == ~1 && t___[1] == ~2 && t___[2] == ~3);
93+
b___ = !mint3{0, 1, 2};
94+
assert(b___[0] == true && b___[1] == false && b___[2] == false);
95+
8696
return 0;
8797
}

0 commit comments

Comments
 (0)