From 0a609930802f1572b55402f0af5ff264ab31ece0 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Thu, 19 Oct 2017 16:13:58 -0700 Subject: [PATCH] Use nullptr rather than 0 for a null pointer Summary: This time aided by clang-tidy's modernize-use-nullptr check. Reviewed By: yfeldblum Differential Revision: D6102739 fbshipit-source-id: aeb4bd0a8078d81cc88b766e0a034a37dd25fd1f --- folly/AtomicHashArray-inl.h | 13 ++++++------- folly/AtomicHashMap-inl.h | 14 ++++++-------- folly/ConcurrentSkipList.h | 8 +++++--- folly/FBString.h | 8 ++++---- folly/Foreach.h | 2 +- folly/LockTraits.h | 6 +++--- folly/small_vector.h | 2 +- folly/test/FBStringTest.cpp | 2 +- folly/test/MPMCQueueTest.cpp | 2 +- 9 files changed, 28 insertions(+), 29 deletions(-) diff --git a/folly/AtomicHashArray-inl.h b/folly/AtomicHashArray-inl.h index 5b818379..f8251f33 100644 --- a/folly/AtomicHashArray-inl.h +++ b/folly/AtomicHashArray-inl.h @@ -414,18 +414,17 @@ struct AtomicHashArray { - explicit aha_iterator() : aha_(0) {} + explicit aha_iterator() : aha_(nullptr) {} // Conversion ctor for interoperability between const_iterator and // iterator. The enable_if<> magic keeps us well-behaved for // is_convertible<> (v. the iterator_facade documentation). template - aha_iterator(const aha_iterator& o, - typename std::enable_if< - std::is_convertible::value >::type* = 0) - : aha_(o.aha_) - , offset_(o.offset_) - {} + aha_iterator( + const aha_iterator& o, + typename std::enable_if< + std::is_convertible::value>::type* = nullptr) + : aha_(o.aha_), offset_(o.offset_) {} explicit aha_iterator(ContT* array, size_t offset) : aha_(array) diff --git a/folly/AtomicHashMap-inl.h b/folly/AtomicHashMap-inl.h index b4032ab2..ee3da5da 100644 --- a/folly/AtomicHashMap-inl.h +++ b/folly/AtomicHashMap-inl.h @@ -468,19 +468,17 @@ struct AtomicHashMap, IterVal, boost::forward_traversal_tag> { - explicit ahm_iterator() : ahm_(0) {} + explicit ahm_iterator() : ahm_(nullptr) {} // Conversion ctor for interoperability between const_iterator and // iterator. The enable_if<> magic keeps us well-behaved for // is_convertible<> (v. the iterator_facade documentation). template - ahm_iterator(const ahm_iterator& o, - typename std::enable_if< - std::is_convertible::value >::type* = 0) - : ahm_(o.ahm_) - , subMap_(o.subMap_) - , subIt_(o.subIt_) - {} + ahm_iterator( + const ahm_iterator& o, + typename std::enable_if< + std::is_convertible::value>::type* = nullptr) + : ahm_(o.ahm_), subMap_(o.subMap_), subIt_(o.subIt_) {} /* * Returns the unique index that can be used for access directly diff --git a/folly/ConcurrentSkipList.h b/folly/ConcurrentSkipList.h index 7d511aad..a4b749bb 100644 --- a/folly/ConcurrentSkipList.h +++ b/folly/ConcurrentSkipList.h @@ -676,9 +676,11 @@ class detail::csl_iterator : explicit csl_iterator(NodeT* node = nullptr) : node_(node) {} template - csl_iterator(const csl_iterator &other, - typename std::enable_if::value>::type* - = 0) : node_(other.node_) {} + csl_iterator( + const csl_iterator& other, + typename std::enable_if< + std::is_convertible::value>::type* = nullptr) + : node_(other.node_) {} size_t nodeSize() const { return node_ == nullptr ? 0 : diff --git a/folly/FBString.h b/folly/FBString.h index 731b3d9c..af49ebe0 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -2333,7 +2333,7 @@ basic_fbstring::find_first_of( } const_iterator i(begin() + pos), finish(end()); for (; i != finish; ++i) { - if (traits_type::find(s, n, *i) != 0) { + if (traits_type::find(s, n, *i) != nullptr) { return i - begin(); } } @@ -2348,7 +2348,7 @@ basic_fbstring::find_last_of( pos = std::min(pos, length() - 1); const_iterator i(begin() + pos); for (;; --i) { - if (traits_type::find(s, n, *i) != 0) { + if (traits_type::find(s, n, *i) != nullptr) { return i - begin(); } if (i == begin()) { @@ -2366,7 +2366,7 @@ basic_fbstring::find_first_not_of( if (pos < length()) { const_iterator i(begin() + pos), finish(end()); for (; i != finish; ++i) { - if (traits_type::find(s, n, *i) == 0) { + if (traits_type::find(s, n, *i) == nullptr) { return i - begin(); } } @@ -2382,7 +2382,7 @@ basic_fbstring::find_last_not_of( pos = std::min(pos, size() - 1); const_iterator i(begin() + pos); for (;; --i) { - if (traits_type::find(s, n, *i) == 0) { + if (traits_type::find(s, n, *i) == nullptr) { return i - begin(); } if (i == begin()) { diff --git a/folly/Foreach.h b/folly/Foreach.h index 50740f40..ae0e865d 100644 --- a/folly/Foreach.h +++ b/folly/Foreach.h @@ -216,7 +216,7 @@ class HasLess { template static BiggerThanChar test(...); public: - enum { value = sizeof(test(0)) == 1 }; + enum { value = sizeof(test(nullptr)) == 1 }; }; /** diff --git a/folly/LockTraits.h b/folly/LockTraits.h index 983831e0..a6cf12b5 100644 --- a/folly/LockTraits.h +++ b/folly/LockTraits.h @@ -106,11 +106,11 @@ class LockInterfaceDispatcher { public: static constexpr bool has_lock_unique = true; static constexpr bool has_lock_timed = - decltype(timed_lock_test(0))::value; + decltype(timed_lock_test(nullptr))::value; static constexpr bool has_lock_shared = - decltype(lock_shared_test(0))::value; + decltype(lock_shared_test(nullptr))::value; static constexpr bool has_lock_upgrade = - decltype(lock_upgrade_test(0))::value; + decltype(lock_upgrade_test(nullptr))::value; }; /** diff --git a/folly/small_vector.h b/folly/small_vector.h index b8009b01..71440437 100644 --- a/folly/small_vector.h +++ b/folly/small_vector.h @@ -1137,7 +1137,7 @@ class small_vector : public detail::small_vector_base< union Data { explicit Data() { - pdata_.heap_ = 0; + pdata_.heap_ = nullptr; } PointerType pdata_; diff --git a/folly/test/FBStringTest.cpp b/folly/test/FBStringTest.cpp index 64343b40..6ded8b4c 100644 --- a/folly/test/FBStringTest.cpp +++ b/folly/test/FBStringTest.cpp @@ -1236,7 +1236,7 @@ TEST(FBString, testMoveOperatorPlusRhs) { // other than libstdc++. Someday if we deem it important to present // identical undefined behavior for other platforms, we can re-visit this. TEST(FBString, testConstructionFromLiteralZero) { - EXPECT_THROW(fbstring s(0), std::logic_error); + EXPECT_THROW(fbstring s(nullptr), std::logic_error); } TEST(FBString, testFixedBugs) { diff --git a/folly/test/MPMCQueueTest.cpp b/folly/test/MPMCQueueTest.cpp index 0874a8f2..18399036 100644 --- a/folly/test/MPMCQueueTest.cpp +++ b/folly/test/MPMCQueueTest.cpp @@ -348,7 +348,7 @@ TEST(MPMCQueue, mt_try_enq_deq_deterministic) { uint64_t nowMicro() { timeval tv; - gettimeofday(&tv, 0); + gettimeofday(&tv, nullptr); return static_cast(tv.tv_sec) * 1000000 + tv.tv_usec; } -- 2.34.1