Skip to content

Commit

Permalink
Fix a few issues found by CppCheck
Browse files Browse the repository at this point in the history
- `multi_ptr &operator=` should return `*this`
- `context::get_devices` returns a temporary, so we should not mix
  iterators from multiple calls to it.
  • Loading branch information
al42and committed Dec 19, 2024
1 parent f661744 commit 8900c30
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 18 additions & 4 deletions include/simsycl/sycl/multi_ptr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ class multi_ptr {
requires(Space == access::address_space::generic_space && AS != access::address_space::constant_space)
multi_ptr &operator=(const multi_ptr<value_type, AS, IsDecorated> &other) {
m_ptr = other.m_ptr;
return *this;
}

template<access::address_space AS, access::decorated IsDecorated>
requires(Space == access::address_space::generic_space && AS != access::address_space::constant_space)
multi_ptr &operator=(multi_ptr<value_type, AS, IsDecorated> &&other) {
m_ptr = other.m_ptr;
return *this;
}

reference operator[](std::ptrdiff_t i) const { return m_ptr[i]; }
Expand Down Expand Up @@ -411,8 +413,14 @@ class SIMSYCL_DETAIL_DEPRECATED_IN_SYCL multi_ptr<ElementType, Space, access::de
// Assignment and access operators
multi_ptr &operator=(const multi_ptr &) = default;
multi_ptr &operator=(multi_ptr &&) = default;
multi_ptr &operator=(pointer_t ptr) { m_ptr = ptr; }
multi_ptr &operator=(std::nullptr_t /* nullptr */) { m_ptr = nullptr; }
multi_ptr &operator=(pointer_t ptr) {
m_ptr = ptr;
return *this;
}
multi_ptr &operator=(std::nullptr_t /* nullptr */) {
m_ptr = nullptr;
return *this;
}

ElementType *operator->() const { return m_ptr; }

Expand Down Expand Up @@ -556,8 +564,14 @@ class SIMSYCL_DETAIL_DEPRECATED_IN_SYCL
// Assignment operators
multi_ptr &operator=(const multi_ptr &) = default;
multi_ptr &operator=(multi_ptr &&) = default;
multi_ptr &operator=(pointer_t ptr) { m_ptr = ptr; }
multi_ptr &operator=(std::nullptr_t /* nullptr */) { m_ptr = nullptr; }
multi_ptr &operator=(pointer_t ptr) {
m_ptr = ptr;
return *this;
}
multi_ptr &operator=(std::nullptr_t /* nullptr */) {
m_ptr = nullptr;
return *this;
}

template<typename ElementType, int Dimensions, access_mode Mode, access::placeholder IsPlaceholder>
requires(Space == access::address_space::global_space || Space == access::address_space::generic_space)
Expand Down
4 changes: 2 additions & 2 deletions src/simsycl/queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ struct queue_state {

queue_state(const sycl::device &device, const sycl::context &context, const sycl::async_handler &async_handler)
: device(device), context(context), async_handler(async_handler) {
SIMSYCL_CHECK_MSG(std::find(context.get_devices().begin(), context.get_devices().end(), device)
!= context.get_devices().end(),
const auto devices = context.get_devices();
SIMSYCL_CHECK_MSG(std::find(devices.begin(), devices.end(), device) != devices.end(),
"queue::queue(): selected device is not in provided context");
}

Expand Down

0 comments on commit 8900c30

Please sign in to comment.