Skip to content

Commit 488c7c9

Browse files
[SYCL] Fix weak_object move and copy assignment (#8716)
This commit fixes an issue where the copy and move assignment operators of the weak_object class would be implicitly deleted due to them being missing from the base class. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent ea26922 commit 488c7c9

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

sycl/include/sycl/ext/oneapi/weak_object_base.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ template <typename SYCLObjT> class weak_object_base {
3333
weak_object_base(const weak_object_base &Other) noexcept = default;
3434
weak_object_base(weak_object_base &&Other) noexcept = default;
3535

36+
weak_object_base &operator=(const weak_object_base &Other) noexcept = default;
37+
weak_object_base &operator=(weak_object_base &&Other) noexcept = default;
38+
3639
void reset() noexcept { MObjWeakPtr.reset(); }
3740
void swap(weak_object_base &Other) noexcept {
3841
MObjWeakPtr.swap(Other.MObjWeakPtr);

sycl/unittests/Extensions/WeakObject.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,39 @@ template <typename SyclObjT> struct WeakObjectCheckOwnerLessMap {
198198
}
199199
};
200200

201+
template <typename SyclObjT> struct WeakObjectCheckCopy {
202+
void operator()(SyclObjT Obj) {
203+
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj{Obj};
204+
205+
sycl::ext::oneapi::weak_object<SyclObjT> WeakObjCopyCtor{WeakObj};
206+
sycl::ext::oneapi::weak_object<SyclObjT> WeakObjCopyAssign = WeakObj;
207+
208+
EXPECT_FALSE(WeakObjCopyCtor.expired());
209+
EXPECT_FALSE(WeakObjCopyAssign.expired());
210+
211+
EXPECT_TRUE(WeakObjCopyCtor.lock() == Obj);
212+
EXPECT_TRUE(WeakObjCopyAssign.lock() == Obj);
213+
}
214+
};
215+
216+
template <typename SyclObjT> struct WeakObjectCheckMove {
217+
void operator()(SyclObjT Obj) {
218+
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj1{Obj};
219+
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj2{Obj};
220+
221+
sycl::ext::oneapi::weak_object<SyclObjT> WeakObjMoveCtor{
222+
std::move(WeakObj1)};
223+
sycl::ext::oneapi::weak_object<SyclObjT> WeakObjMoveAssign =
224+
std::move(WeakObj2);
225+
226+
EXPECT_FALSE(WeakObjMoveCtor.expired());
227+
EXPECT_FALSE(WeakObjMoveAssign.expired());
228+
229+
EXPECT_TRUE(WeakObjMoveCtor.lock() == Obj);
230+
EXPECT_TRUE(WeakObjMoveAssign.lock() == Obj);
231+
}
232+
};
233+
201234
template <template <typename> typename CallableT>
202235
void runTest(sycl::unittest::PiMock &Mock) {
203236
sycl::platform Plt = Mock.getPlatform();
@@ -385,3 +418,13 @@ TEST(WeakObjectTest, WeakObjectOwnerLessMap) {
385418
sycl::unittest::PiMock Mock;
386419
runTestMulti<WeakObjectCheckOwnerLessMap>(Mock);
387420
}
421+
422+
TEST(WeakObjectTest, WeakObjectCopy) {
423+
sycl::unittest::PiMock Mock;
424+
runTest<WeakObjectCheckCopy>(Mock);
425+
}
426+
427+
TEST(WeakObjectTest, WeakObjectMove) {
428+
sycl::unittest::PiMock Mock;
429+
runTest<WeakObjectCheckMove>(Mock);
430+
}

0 commit comments

Comments
 (0)