Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Use the nullptr literal instead of std::nullptr_t parameters in
Browse files Browse the repository at this point in the history
`thrust::pointer` and `thrust::device_ptr` to silence spurious "set but not
used" warnings from old GCC versions.
  • Loading branch information
brycelelbach committed Feb 10, 2022
1 parent 486d858 commit ee638c2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions thrust/detail/pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

/*! \file
/*! \file
* \brief A pointer to a variable which resides in memory associated with a
* system.
*/
Expand Down Expand Up @@ -235,19 +235,19 @@ operator<<(std::basic_ostream<charT, traits> &os,
// `std::unique_ptr`.
template <typename Element, typename Tag, typename Reference, typename Derived>
__host__ __device__
bool operator==(std::nullptr_t np, pointer<Element, Tag, Reference, Derived> p);
bool operator==(std::nullptr_t, pointer<Element, Tag, Reference, Derived> p);

template <typename Element, typename Tag, typename Reference, typename Derived>
__host__ __device__
bool operator==(pointer<Element, Tag, Reference, Derived> p, std::nullptr_t np);
bool operator==(pointer<Element, Tag, Reference, Derived> p, std::nullptr_t);

template <typename Element, typename Tag, typename Reference, typename Derived>
__host__ __device__
bool operator!=(std::nullptr_t np, pointer<Element, Tag, Reference, Derived> p);
bool operator!=(std::nullptr_t, pointer<Element, Tag, Reference, Derived> p);

template <typename Element, typename Tag, typename Reference, typename Derived>
__host__ __device__
bool operator!=(pointer<Element, Tag, Reference, Derived> p, std::nullptr_t np);
bool operator!=(pointer<Element, Tag, Reference, Derived> p, std::nullptr_t);

THRUST_NAMESPACE_END

Expand Down
20 changes: 10 additions & 10 deletions thrust/detail/pointer.inl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ template<typename Element, typename Tag, typename Reference, typename Derived>
template<typename Element, typename Tag, typename Reference, typename Derived>
__host__ __device__
pointer<Element,Tag,Reference,Derived>
::pointer(std::nullptr_t np)
: super_t(static_cast<Element*>(np))
::pointer(std::nullptr_t)
: super_t(static_cast<Element*>(nullptr))
{} // end pointer::pointer


Expand Down Expand Up @@ -180,30 +180,30 @@ operator<<(std::basic_ostream<charT, traits> &os,
// `std::unique_ptr`.
template <typename Element, typename Tag, typename Reference, typename Derived>
__host__ __device__
bool operator==(std::nullptr_t np, pointer<Element, Tag, Reference, Derived> p)
bool operator==(std::nullptr_t, pointer<Element, Tag, Reference, Derived> p)
{
return np == p.get();
return nullptr == p.get();
}

template <typename Element, typename Tag, typename Reference, typename Derived>
__host__ __device__
bool operator==(pointer<Element, Tag, Reference, Derived> p, std::nullptr_t np)
bool operator==(pointer<Element, Tag, Reference, Derived> p, std::nullptr_t)
{
return np == p.get();
return nullptr == p.get();
}

template <typename Element, typename Tag, typename Reference, typename Derived>
__host__ __device__
bool operator!=(std::nullptr_t np, pointer<Element, Tag, Reference, Derived> p)
bool operator!=(std::nullptr_t, pointer<Element, Tag, Reference, Derived> p)
{
return !(np == p);
return !(nullptr == p);
}

template <typename Element, typename Tag, typename Reference, typename Derived>
__host__ __device__
bool operator!=(pointer<Element, Tag, Reference, Derived> p, std::nullptr_t np)
bool operator!=(pointer<Element, Tag, Reference, Derived> p, std::nullptr_t)
{
return !(np == p);
return !(nullptr == p);
}

THRUST_NAMESPACE_END
6 changes: 3 additions & 3 deletions thrust/device_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class device_ptr
* \post <tt>get() == nullptr</tt>.
*/
__host__ __device__
device_ptr(std::nullptr_t ptr) : super_t(ptr) {}
device_ptr(std::nullptr_t) : super_t(nullptr) {}

/*! \brief Construct a \c device_ptr from a raw pointer which is
* convertible to \c T*.
Expand Down Expand Up @@ -153,9 +153,9 @@ class device_ptr
* \return \c *this.
*/
__host__ __device__
device_ptr& operator=(std::nullptr_t ptr)
device_ptr& operator=(std::nullptr_t)
{
super_t::operator=(ptr);
super_t::operator=(nullptr);
return *this;
}

Expand Down

0 comments on commit ee638c2

Please sign in to comment.