Skip to content

[SYCL] Add copy/move ctors and assignment operators to sycl::detail::optional #19775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions devops/compat_ci_exclude.sycl-rel-6_2
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ AsyncAlloc/device/ooo_queue_async_alloc_from_pool.cpp

# Need more investigation by the author:

# https://github.com/intel/llvm/pull/18314
Assert/assert_in_kernels.cpp
Assert/assert_in_multiple_tus.cpp
Assert/assert_in_multiple_tus_one_ndebug.cpp
Assert/assert_in_one_kernel.cpp
Assert/assert_in_simultaneous_kernels.cpp
Assert/assert_in_simultaneously_multiple_tus.cpp
Assert/assert_in_simultaneously_multiple_tus_one_ndebug.cpp

# https://github.com/intel/llvm/pull/18403 (pulldown, so probably offload-tools
# team should be looking into this)
DeviceImageDependencies/NewOffloadDriver/dynamic.cpp
Expand Down
24 changes: 24 additions & 0 deletions sycl/include/sycl/detail/optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ template <typename T> class optional {
public:
constexpr optional() noexcept {}
constexpr optional(std::nullopt_t) noexcept : optional() {}
constexpr optional(const optional &Other)
: ContainsValue{Other.ContainsValue} {
if (Other.ContainsValue)
new (Storage) T(Other.value());
}
constexpr optional(optional &&Other) : ContainsValue{Other.ContainsValue} {
new (Storage) T(std::move(Other.value()));
Other.ContainsValue = false;
}

template <typename U>
constexpr optional(const optional<U> &Other)
Expand Down Expand Up @@ -60,6 +69,21 @@ template <typename T> class optional {
return *this;
}

optional &operator=(const optional<T> &Other) {
if (has_value())
reinterpret_cast<T *>(Storage)->~T();
ContainsValue = Other.has_value();
new (Storage) T(Other.value());
return *this;
}
optional &operator=(optional<T> &&Other) noexcept {
if (has_value())
reinterpret_cast<T *>(Storage)->~T();
ContainsValue = Other.has_value();
new (Storage) T(std::move(Other.value()));
return *this;
}

template <typename U> optional &operator=(const optional<U> &Other) {
if (has_value())
reinterpret_cast<T *>(Storage)->~T();
Expand Down
Loading