From: Christopher Dykes Date: Thu, 19 Oct 2017 18:04:53 +0000 (-0700) Subject: Ensure curly-braces around control-flow X-Git-Tag: v2017.10.23.00~13 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7ebe7c2a249de44209e8bcc453e1a70bafd4ed19;p=folly.git Ensure curly-braces around control-flow Summary: The style guidelines say control flow should always have curly braces, and we follow that, mostly. This just uses clang-tidy to clean up everywhere that we weren't. Reviewed By: markisaa, luciang Differential Revision: D6097377 fbshipit-source-id: bfe6766c37bd863ecf68851ef93265a200d4259d --- diff --git a/folly/AtomicHashMap-inl.h b/folly/AtomicHashMap-inl.h index 2dc55255..b4032ab2 100644 --- a/folly/AtomicHashMap-inl.h +++ b/folly/AtomicHashMap-inl.h @@ -439,7 +439,9 @@ AtomicHashMap:: encodeIndex(uint32_t subMap, uint32_t offset) { DCHECK_EQ(offset & kSecondaryMapBit_, 0); // offset can't be too big - if (subMap == 0) return offset; + if (subMap == 0) { + return offset; + } // Make sure subMap isn't too big DCHECK_EQ(subMap >> kNumSubMapBits_, 0); // Make sure subMap bits of offset are clear diff --git a/folly/ConcurrentSkipList-inl.h b/folly/ConcurrentSkipList-inl.h index ac6023aa..eca30ceb 100644 --- a/folly/ConcurrentSkipList-inl.h +++ b/folly/ConcurrentSkipList-inl.h @@ -138,7 +138,9 @@ class SkipListNode : private boost::noncopyable { height_(height), data_(std::forward(data)) { spinLock_.init(); setFlags(0); - if (isHead) setIsHeadNode(); + if (isHead) { + setIsHeadNode(); + } // need to explicitly init the dynamic atomic pointer array for (uint8_t i = 0; i < height_; ++i) { new (&skip_[i]) std::atomic(nullptr); diff --git a/folly/ConcurrentSkipList.h b/folly/ConcurrentSkipList.h index 1a2fdadc..7d511aad 100644 --- a/folly/ConcurrentSkipList.h +++ b/folly/ConcurrentSkipList.h @@ -258,7 +258,9 @@ class ConcurrentSkipList { // Returns the node if found, nullptr otherwise. NodeType* find(const value_type &data) { auto ret = findNode(data); - if (ret.second && !ret.first->markedForRemoval()) return ret.first; + if (ret.second && !ret.first->markedForRemoval()) { + return ret.first; + } return nullptr; } @@ -369,7 +371,9 @@ class ConcurrentSkipList { nodeToDelete = succs[layer]; nodeHeight = nodeToDelete->height(); nodeGuard = nodeToDelete->acquireGuard(); - if (nodeToDelete->markedForRemoval()) return false; + if (nodeToDelete->markedForRemoval()) { + return false; + } nodeToDelete->setMarkedForRemoval(); isMarked = true; } @@ -402,7 +406,9 @@ class ConcurrentSkipList { for (int layer = maxLayer(); layer >= 0; --layer) { do { node = pred->skip(layer); - if (node) pred = node; + if (node) { + pred = node; + } } while (node != nullptr); } return pred == head_.load(std::memory_order_relaxed) @@ -445,7 +451,9 @@ class ConcurrentSkipList { while (!found) { // stepping down for (; ht > 0 && less(data, node = pred->skip(ht - 1)); --ht) {} - if (ht == 0) return std::make_pair(node, 0); // not found + if (ht == 0) { + return std::make_pair(node, 0); // not found + } // node <= data now, but we need to fix up ht --ht; @@ -773,7 +781,9 @@ class ConcurrentSkipList::Skipper { */ bool to(const value_type &data) { int layer = curHeight() - 1; - if (layer < 0) return false; // reaches the end of the list + if (layer < 0) { + return false; // reaches the end of the list + } int lyr = hints_[layer]; int max_layer = maxLayer(); @@ -784,7 +794,9 @@ class ConcurrentSkipList::Skipper { int foundLayer = SkipListType:: findInsertionPoint(preds_[lyr], lyr, data, preds_, succs_); - if (foundLayer < 0) return false; + if (foundLayer < 0) { + return false; + } DCHECK(succs_[0] != nullptr) << "lyr=" << lyr << "; max_layer=" << max_layer; diff --git a/folly/Conv.h b/folly/Conv.h index ff3bb81d..351fd4f9 100644 --- a/folly/Conv.h +++ b/folly/Conv.h @@ -1426,8 +1426,9 @@ using ParseToResult = decltype(parseTo(StringPiece{}, std::declval())); struct CheckTrailingSpace { Expected operator()(StringPiece sp) const { auto e = enforceWhitespaceErr(sp); - if (UNLIKELY(e != ConversionCode::SUCCESS)) + if (UNLIKELY(e != ConversionCode::SUCCESS)) { return makeUnexpected(e); + } return unit; } }; diff --git a/folly/DiscriminatedPtr.h b/folly/DiscriminatedPtr.h index 2c57fb6e..f12e3d9c 100644 --- a/folly/DiscriminatedPtr.h +++ b/folly/DiscriminatedPtr.h @@ -173,7 +173,9 @@ class DiscriminatedPtr { template typename dptr_detail::VisitorResult::type apply(V&& visitor) { size_t n = index(); - if (n == 0) throw std::invalid_argument("Empty DiscriminatedPtr"); + if (n == 0) { + throw std::invalid_argument("Empty DiscriminatedPtr"); + } return dptr_detail::ApplyVisitor()( n, std::forward(visitor), ptr()); } @@ -182,7 +184,9 @@ class DiscriminatedPtr { typename dptr_detail::ConstVisitorResult::type apply(V&& visitor) const { size_t n = index(); - if (n == 0) throw std::invalid_argument("Empty DiscriminatedPtr"); + if (n == 0) { + throw std::invalid_argument("Empty DiscriminatedPtr"); + } return dptr_detail::ApplyConstVisitor()( n, std::forward(visitor), ptr()); } diff --git a/folly/Expected.h b/folly/Expected.h index 8f5d9a64..57098e28 100644 --- a/folly/Expected.h +++ b/folly/Expected.h @@ -460,8 +460,9 @@ struct ExpectedStorage } template void assign(Other&& that) { - if (isSelfAssign(&that)) + if (isSelfAssign(&that)) { return; + } switch (that.which_) { case Which::eValue: this->assignValue(static_cast(that).value()); @@ -590,13 +591,14 @@ struct ExpectedHelper { T::template return_( (std::declval()(std::declval().value()), unit)), std::declval()...)) { - if (LIKELY(ex.which_ == expected_detail::Which::eValue)) + if (LIKELY(ex.which_ == expected_detail::Which::eValue)) { return T::then_( T::template return_( // Uses the comma operator defined above IFF the lambda // returns non-void. (static_cast(fn)(static_cast(ex).value()), unit)), static_cast(fns)...); + } return makeUnexpected(static_cast(ex).error()); } @@ -608,8 +610,9 @@ struct ExpectedHelper { class Err = decltype(std::declval()(std::declval().error())) FOLLY_REQUIRES_TRAILING(!std::is_void::value)> static Ret thenOrThrow_(This&& ex, Yes&& yes, No&& no) { - if (LIKELY(ex.which_ == expected_detail::Which::eValue)) + if (LIKELY(ex.which_ == expected_detail::Which::eValue)) { return Ret(static_cast(yes)(static_cast(ex).value())); + } throw static_cast(no)(static_cast(ex).error()); } @@ -621,8 +624,9 @@ struct ExpectedHelper { class Err = decltype(std::declval()(std::declval().error())) FOLLY_REQUIRES_TRAILING(std::is_void::value)> static Ret thenOrThrow_(This&& ex, Yes&& yes, No&& no) { - if (LIKELY(ex.which_ == expected_detail::Which::eValue)) + if (LIKELY(ex.which_ == expected_detail::Which::eValue)) { return Ret(static_cast(yes)(static_cast(ex).value())); + } static_cast(no)(ex.error()); throw typename Unexpected>::MakeBadExpectedAccess()( static_cast(ex).error()); @@ -1041,8 +1045,9 @@ class Expected final : expected_detail::ExpectedStorage { */ void swap(Expected& that) noexcept( expected_detail::StrictAllOf::value) { - if (this->uninitializedByException() || that.uninitializedByException()) + if (this->uninitializedByException() || that.uninitializedByException()) { throw BadExpectedAccess(); + } using std::swap; if (*this) { if (that) { @@ -1180,8 +1185,9 @@ class Expected final : expected_detail::ExpectedStorage { expected_detail::ExpectedHelper::then_( std::declval(), std::declval()...)) { - if (this->uninitializedByException()) + if (this->uninitializedByException()) { throw BadExpectedAccess(); + } return expected_detail::ExpectedHelper::then_( base(), static_cast(fns)...); } @@ -1190,8 +1196,9 @@ class Expected final : expected_detail::ExpectedStorage { auto then(Fns&&... fns) & -> decltype(expected_detail::ExpectedHelper::then_( std::declval(), std::declval()...)) { - if (this->uninitializedByException()) + if (this->uninitializedByException()) { throw BadExpectedAccess(); + } return expected_detail::ExpectedHelper::then_( base(), static_cast(fns)...); } @@ -1200,8 +1207,9 @@ class Expected final : expected_detail::ExpectedStorage { auto then(Fns&&... fns) && -> decltype(expected_detail::ExpectedHelper::then_( std::declval(), std::declval()...)) { - if (this->uninitializedByException()) + if (this->uninitializedByException()) { throw BadExpectedAccess(); + } return expected_detail::ExpectedHelper::then_( std::move(base()), static_cast(fns)...); } @@ -1213,8 +1221,9 @@ class Expected final : expected_detail::ExpectedStorage { auto thenOrThrow(Yes&& yes, No&& no = No{}) const& -> decltype( std::declval()(std::declval())) { using Ret = decltype(std::declval()(std::declval())); - if (this->uninitializedByException()) + if (this->uninitializedByException()) { throw BadExpectedAccess(); + } return Ret(expected_detail::ExpectedHelper::thenOrThrow_( base(), static_cast(yes), static_cast(no))); } @@ -1223,8 +1232,9 @@ class Expected final : expected_detail::ExpectedStorage { auto thenOrThrow(Yes&& yes, No&& no = No{}) & -> decltype( std::declval()(std::declval())) { using Ret = decltype(std::declval()(std::declval())); - if (this->uninitializedByException()) + if (this->uninitializedByException()) { throw BadExpectedAccess(); + } return Ret(expected_detail::ExpectedHelper::thenOrThrow_( base(), static_cast(yes), static_cast(no))); } @@ -1233,8 +1243,9 @@ class Expected final : expected_detail::ExpectedStorage { auto thenOrThrow(Yes&& yes, No&& no = No{}) && -> decltype( std::declval()(std::declval())) { using Ret = decltype(std::declval()(std::declval())); - if (this->uninitializedByException()) + if (this->uninitializedByException()) { throw BadExpectedAccess(); + } return Ret(expected_detail::ExpectedHelper::thenOrThrow_( std::move(base()), static_cast(yes), static_cast(no))); } @@ -1242,8 +1253,9 @@ class Expected final : expected_detail::ExpectedStorage { private: void requireValue() const { if (UNLIKELY(!hasValue())) { - if (LIKELY(hasError())) + if (LIKELY(hasError())) { throw typename Unexpected::BadExpectedAccess(this->error_); + } throw BadExpectedAccess(); } } @@ -1264,13 +1276,16 @@ inline typename std::enable_if::value, bool>::type operator==( const Expected& lhs, const Expected& rhs) { - if (UNLIKELY(lhs.which_ != rhs.which_)) + if (UNLIKELY(lhs.which_ != rhs.which_)) { return UNLIKELY(lhs.uninitializedByException()) ? false : throw BadExpectedAccess(); - if (UNLIKELY(lhs.uninitializedByException())) + } + if (UNLIKELY(lhs.uninitializedByException())) { throw BadExpectedAccess(); - if (UNLIKELY(lhs.hasError())) + } + if (UNLIKELY(lhs.hasError())) { return true; // All error states are considered equal + } return lhs.value_ == rhs.value_; } @@ -1289,12 +1304,15 @@ operator<( const Expected& lhs, const Expected& rhs) { if (UNLIKELY( - lhs.uninitializedByException() || rhs.uninitializedByException())) + lhs.uninitializedByException() || rhs.uninitializedByException())) { throw BadExpectedAccess(); - if (UNLIKELY(lhs.hasError())) + } + if (UNLIKELY(lhs.hasError())) { return !rhs.hasError(); - if (UNLIKELY(rhs.hasError())) + } + if (UNLIKELY(rhs.hasError())) { return false; + } return lhs.value_ < rhs.value_; } diff --git a/folly/FBString.h b/folly/FBString.h index b566d119..731b3d9c 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -1420,7 +1420,9 @@ class basic_fbstring { } basic_fbstring& assign(const basic_fbstring& str) { - if (&str == this) return *this; + if (&str == this) { + return *this; + } return assign(str.data(), str.size()); } diff --git a/folly/FBVector.h b/folly/FBVector.h index 21253afe..c52c3501 100644 --- a/folly/FBVector.h +++ b/folly/FBVector.h @@ -184,7 +184,9 @@ class fbvector { static void swap(Impl& a, Impl& b) { using std::swap; - if (!usingStdAllocator::value) swap(a, b); + if (!usingStdAllocator::value) { + swap(a, b); + } a.swapData(b); } @@ -318,8 +320,9 @@ class fbvector { void M_destroy(T* p) noexcept { if (usingStdAllocator::value) { - if (!std::is_trivially_destructible::value) + if (!std::is_trivially_destructible::value) { p->~T(); + } } else { std::allocator_traits::destroy(impl_, p); } @@ -350,8 +353,9 @@ class fbvector { // allocator static void S_destroy_range_a(Allocator& a, T* first, T* last) noexcept { - for (; first != last; ++first) + for (; first != last; ++first) { std::allocator_traits::destroy(a, first); + } } // optimized @@ -412,9 +416,10 @@ class fbvector { auto b = dest; auto e = dest + sz; try { - for (; b != e; ++b) + for (; b != e; ++b) { std::allocator_traits::construct(a, b, std::forward(args)...); + } } catch (...) { S_destroy_range_a(a, dest, b); throw; @@ -431,10 +436,14 @@ class fbvector { auto b = dest; auto e = dest + n; try { - for (; b != e; ++b) S_construct(b); + for (; b != e; ++b) { + S_construct(b); + } } catch (...) { --b; - for (; b >= dest; --b) b->~T(); + for (; b >= dest; --b) { + b->~T(); + } throw; } } @@ -444,7 +453,9 @@ class fbvector { auto b = dest; auto e = dest + n; try { - for (; b != e; ++b) S_construct(b, value); + for (; b != e; ++b) { + S_construct(b, value); + } } catch (...) { S_destroy_range(dest, b); throw; @@ -496,8 +507,9 @@ class fbvector { S_uninitialized_copy_a(Allocator& a, T* dest, It first, It last) { auto b = dest; try { - for (; first != last; ++first, ++b) + for (; first != last; ++first, ++b) { std::allocator_traits::construct(a, b, *first); + } } catch (...) { S_destroy_range_a(a, dest, b); throw; @@ -509,8 +521,9 @@ class fbvector { static void S_uninitialized_copy(T* dest, It first, It last) { auto b = dest; try { - for (; first != last; ++first, ++b) + for (; first != last; ++first, ++b) { S_construct(b, *first); + } } catch (...) { S_destroy_range(dest, b); throw; @@ -550,7 +563,9 @@ class fbvector { template static It S_copy_n(T* dest, It first, size_type n) { auto e = dest + n; - for (; dest != e; ++dest, ++first) *dest = *first; + for (; dest != e; ++dest, ++first) { + *dest = *first; + } return first; } @@ -725,7 +740,9 @@ class fbvector { ~fbvector() = default; // the cleanup occurs in impl_ fbvector& operator=(const fbvector& other) { - if (UNLIKELY(this == &other)) return *this; + if (UNLIKELY(this == &other)) { + return *this; + } if (!usingStdAllocator::value && A::propagate_on_container_copy_assignment::value) { @@ -741,7 +758,9 @@ class fbvector { } fbvector& operator=(fbvector&& other) { - if (UNLIKELY(this == &other)) return *this; + if (UNLIKELY(this == &other)) { + return *this; + } moveFrom(std::move(other), moveIsSwap()); return *this; } @@ -796,10 +815,16 @@ class fbvector { { M_uninitialized_copy_e(first, last); } template - fbvector(InputIterator first, InputIterator last, - const Allocator& a, std::input_iterator_tag) - : impl_(a) - { for (; first != last; ++first) emplace_back(*first); } + fbvector( + InputIterator first, + InputIterator last, + const Allocator& a, + std::input_iterator_tag) + : impl_(a) { + for (; first != last; ++first) { + emplace_back(*first); + } + } // contract dispatch for allocator movement in operator=(fbvector&&) void @@ -842,13 +867,17 @@ class fbvector { if (p != impl_.e_) { M_destroy_range_e(p); } else { - for (; first != last; ++first) emplace_back(*first); + for (; first != last; ++first) { + emplace_back(*first); + } } } // contract dispatch for aliasing under VT optimization bool dataIsInternalAndNotVT(const T& t) { - if (should_pass_by_value::value) return false; + if (should_pass_by_value::value) { + return false; + } return dataIsInternal(t); } bool dataIsInternal(const T& t) { @@ -943,8 +972,12 @@ class fbvector { } void reserve(size_type n) { - if (n <= capacity()) return; - if (impl_.b_ && reserve_in_place(n)) return; + if (n <= capacity()) { + return; + } + if (impl_.b_ && reserve_in_place(n)) { + return; + } auto newCap = folly::goodMallocSize(n * sizeof(T)) / sizeof(T); auto newB = M_allocate(newCap); @@ -954,8 +987,9 @@ class fbvector { M_deallocate(newB, newCap); throw; } - if (impl_.b_) + if (impl_.b_) { M_deallocate(impl_.b_, size_type(impl_.z_ - impl_.b_)); + } impl_.z_ = newB + newCap; impl_.e_ = newB + (impl_.e_ - impl_.b_); impl_.b_ = newB; @@ -971,7 +1005,9 @@ class fbvector { auto const newCap = newCapacityBytes / sizeof(T); auto const oldCap = capacity(); - if (newCap >= oldCap) return; + if (newCap >= oldCap) { + return; + } void* p = impl_.b_; // xallocx() will shrink to precisely newCapacityBytes (which was generated @@ -993,8 +1029,9 @@ class fbvector { } catch (...) { return; } - if (impl_.b_) + if (impl_.b_) { M_deallocate(impl_.b_, size_type(impl_.z_ - impl_.b_)); + } impl_.z_ = newB + newCap; impl_.e_ = newB + (impl_.e_ - impl_.b_); impl_.b_ = newB; @@ -1003,11 +1040,15 @@ class fbvector { private: bool reserve_in_place(size_type n) { - if (!usingStdAllocator::value || !usingJEMalloc()) return false; + if (!usingStdAllocator::value || !usingJEMalloc()) { + return false; + } // jemalloc can never grow in place blocks smaller than 4096 bytes. if ((impl_.z_ - impl_.b_) * sizeof(T) < - folly::jemallocMinInPlaceExpandable) return false; + folly::jemallocMinInPlaceExpandable) { + return false; + } auto const newCapacityBytes = folly::goodMallocSize(n * sizeof(T)); void* p = impl_.b_; @@ -1109,10 +1150,11 @@ class fbvector { } void swap(fbvector& other) noexcept { - if (!usingStdAllocator::value && - A::propagate_on_container_swap::value) + if (!usingStdAllocator::value && A::propagate_on_container_swap::value) { swap(impl_, other.impl_); - else impl_.swapData(other.impl_); + } else { + impl_.swapData(other.impl_); + } } void clear() noexcept { @@ -1313,12 +1355,18 @@ class fbvector { bool insert_use_fresh(bool at_end, size_type n) { if (at_end) { - if (size() + n <= capacity()) return false; - if (reserve_in_place(size() + n)) return false; + if (size() + n <= capacity()) { + return false; + } + if (reserve_in_place(size() + n)) { + return false; + } return true; } - if (size() + n > capacity()) return true; + if (size() + n > capacity()) { + return true; + } return false; } @@ -1484,7 +1532,9 @@ class fbvector { std::make_move_iterator(end()), A::select_on_container_copy_construction(impl_)); M_destroy_range_e(position); - for (; first != last; ++first) emplace_back(*first); + for (; first != last; ++first) { + emplace_back(*first); + } insert(cend(), std::make_move_iterator(storage.begin()), std::make_move_iterator(storage.end())); return impl_.b_ + idx; @@ -1597,7 +1647,9 @@ void fbvector::emplace_back_aux(Args&&... args) { M_deallocate(newB, sz); throw; } - if (impl_.b_) M_deallocate(impl_.b_, size()); + if (impl_.b_) { + M_deallocate(impl_.b_, size()); + } impl_.b_ = newB; impl_.e_ = newE; impl_.z_ = newB + sz; diff --git a/folly/File.cpp b/folly/File.cpp index 74d8669e..9fb755a8 100644 --- a/folly/File.cpp +++ b/folly/File.cpp @@ -138,7 +138,9 @@ void File::doLock(int op) { bool File::doTryLock(int op) { int r = flockNoInt(fd_, op | LOCK_NB); // flock returns EWOULDBLOCK if already locked - if (r == -1 && errno == EWOULDBLOCK) return false; + if (r == -1 && errno == EWOULDBLOCK) { + return false; + } checkUnixError(r, "flock() failed (try_lock)"); return true; } diff --git a/folly/FileUtil.h b/folly/FileUtil.h index 92598093..0913b23d 100644 --- a/folly/FileUtil.h +++ b/folly/FileUtil.h @@ -131,7 +131,9 @@ bool readFile( // Obtain file size: struct stat buf; - if (fstat(fd, &buf) == -1) return false; + if (fstat(fd, &buf) == -1) { + return false; + } // Some files (notably under /proc and /sys on Linux) lie about // their size, so treat the size advertised by fstat under advise // but don't rely on it. In particular, if the size is zero, we diff --git a/folly/Fingerprint.h b/folly/Fingerprint.h index 558cfd59..26d1dc9b 100644 --- a/folly/Fingerprint.h +++ b/folly/Fingerprint.h @@ -99,8 +99,9 @@ class Fingerprint { Fingerprint() { // Use a non-zero starting value. We'll use (1 << (BITS-1)) fp_[0] = 1ULL << 63; - for (int i = 1; i < size(); i++) + for (int i = 1; i < size(); i++) { fp_[i] = 0; + } } Fingerprint& update8(uint8_t v) { diff --git a/folly/FixedString.h b/folly/FixedString.h index 732ae6ac..d91ce1a0 100644 --- a/folly/FixedString.h +++ b/folly/FixedString.h @@ -1242,8 +1242,9 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { std::size_t count, Char ch) noexcept(false) { detail::fixedstring::checkOverflow(count, N - size_); - for (std::size_t i = 0u; i < count; ++i) + for (std::size_t i = 0u; i < count; ++i) { data_[size_ + i] = ch; + } size_ += count; data_[size_] = Char(0); return *this; @@ -1290,8 +1291,9 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { detail::fixedstring::checkOverflow(pos, that.size_); count = detail::fixedstring::checkOverflowOrNpos(count, that.size_ - pos); detail::fixedstring::checkOverflow(count, N - size_); - for (std::size_t i = 0u; i < count; ++i) + for (std::size_t i = 0u; i < count; ++i) { data_[size_ + i] = that.data_[pos + i]; + } size_ += count; data_[size_] = Char(0); return *this; @@ -1318,8 +1320,9 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { const Char* that, std::size_t count) noexcept(false) { detail::fixedstring::checkOverflow(count, N - size_); - for (std::size_t i = 0u; i < count; ++i) + for (std::size_t i = 0u; i < count; ++i) { data_[size_ + i] = that[i]; + } size_ += count; data_[size_] = Char(0); return *this; @@ -2027,8 +2030,9 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { copy(Char* dest, std::size_t count, std::size_t pos) const noexcept(false) { detail::fixedstring::checkOverflow(pos, size_); for (std::size_t i = 0u; i < count; ++i) { - if (i + pos == size_) + if (i + pos == size_) { return size_; + } dest[i] = data_[i + pos]; } return count; diff --git a/folly/Foreach.h b/folly/Foreach.h index 34d074f1..50740f40 100644 --- a/folly/Foreach.h +++ b/folly/Foreach.h @@ -291,7 +291,9 @@ downTo(T& iter, const U& begin) { template typename std::enable_if::value, bool>::type downTo(T& iter, const U& begin) { - if (iter == begin) return false; + if (iter == begin) { + return false; + } --iter; return true; } diff --git a/folly/Format.cpp b/folly/Format.cpp index bbcd2d00..380cddbe 100644 --- a/folly/Format.cpp +++ b/folly/Format.cpp @@ -179,7 +179,9 @@ void FormatArg::initSlow() { if (*p == ':') { // parse format spec - if (++p == end) return; + if (++p == end) { + return; + } // fill/align, or just align Align a; @@ -189,30 +191,40 @@ void FormatArg::initSlow() { fill = *p; align = a; p += 2; - if (p == end) return; + if (p == end) { + return; + } } else if ((a = formatAlignTable[static_cast(*p)]) != Align::INVALID) { align = a; - if (++p == end) return; + if (++p == end) { + return; + } } Sign s; unsigned char uSign = static_cast(*p); if ((s = formatSignTable[uSign]) != Sign::INVALID) { sign = s; - if (++p == end) return; + if (++p == end) { + return; + } } if (*p == '#') { basePrefix = true; - if (++p == end) return; + if (++p == end) { + return; + } } if (*p == '0') { enforce(align == Align::DEFAULT, "alignment specified twice"); fill = '0'; align = Align::PAD_AFTER_SIGN; - if (++p == end) return; + if (++p == end) { + return; + } } auto readInt = [&] { @@ -227,20 +239,30 @@ void FormatArg::initSlow() { width = kDynamicWidth; ++p; - if (p == end) return; + if (p == end) { + return; + } - if (*p >= '0' && *p <= '9') widthIndex = readInt(); + if (*p >= '0' && *p <= '9') { + widthIndex = readInt(); + } - if (p == end) return; + if (p == end) { + return; + } } else if (*p >= '0' && *p <= '9') { width = readInt(); - if (p == end) return; + if (p == end) { + return; + } } if (*p == ',') { thousandsSeparator = true; - if (++p == end) return; + if (++p == end) { + return; + } } if (*p == '.') { @@ -258,11 +280,15 @@ void FormatArg::initSlow() { trailingDot = true; } - if (p == end) return; + if (p == end) { + return; + } } presentation = *p; - if (++p == end) return; + if (++p == end) { + return; + } } error("extra characters in format string"); diff --git a/folly/GroupVarint.h b/folly/GroupVarint.h index 6f1807d2..ed7dae63 100644 --- a/folly/GroupVarint.h +++ b/folly/GroupVarint.h @@ -107,13 +107,21 @@ class GroupVarint : public detail::GroupVarintBase { uint8_t v = uint8_t(*p); size_t s = kHeaderSize; s += 1 + b0key(v); - if (s > size) return 0; + if (s > size) { + return 0; + } s += 1 + b1key(v); - if (s > size) return 1; + if (s > size) { + return 1; + } s += 1 + b2key(v); - if (s > size) return 2; + if (s > size) { + return 2; + } s += 1 + b3key(v); - if (s > size) return 3; + if (s > size) { + return 3; + } return 4; } @@ -312,15 +320,25 @@ class GroupVarint : public detail::GroupVarintBase { uint16_t v = loadUnaligned(p); size_t s = kHeaderSize; s += 1 + b0key(v); - if (s > size) return 0; + if (s > size) { + return 0; + } s += 1 + b1key(v); - if (s > size) return 1; + if (s > size) { + return 1; + } s += 1 + b2key(v); - if (s > size) return 2; + if (s > size) { + return 2; + } s += 1 + b3key(v); - if (s > size) return 3; + if (s > size) { + return 3; + } s += 1 + b4key(v); - if (s > size) return 4; + if (s > size) { + return 4; + } return 5; } diff --git a/folly/Lazy.h b/folly/Lazy.h index afab2faa..a4fcfd35 100644 --- a/folly/Lazy.h +++ b/folly/Lazy.h @@ -107,7 +107,9 @@ struct Lazy { } result_type& operator()() { - if (!value_) value_ = func_(); + if (!value_) { + value_ = func_(); + } return *value_; } diff --git a/folly/Malloc.h b/folly/Malloc.h index 388a1667..71f37ca2 100644 --- a/folly/Malloc.h +++ b/folly/Malloc.h @@ -223,19 +223,25 @@ static const size_t jemallocMinInPlaceExpandable = 4096; */ inline void* checkedMalloc(size_t size) { void* p = malloc(size); - if (!p) std::__throw_bad_alloc(); + if (!p) { + std::__throw_bad_alloc(); + } return p; } inline void* checkedCalloc(size_t n, size_t size) { void* p = calloc(n, size); - if (!p) std::__throw_bad_alloc(); + if (!p) { + std::__throw_bad_alloc(); + } return p; } inline void* checkedRealloc(void* ptr, size_t size) { void* p = realloc(ptr, size); - if (!p) std::__throw_bad_alloc(); + if (!p) { + std::__throw_bad_alloc(); + } return p; } diff --git a/folly/Memory.h b/folly/Memory.h index 121f43db..c1766277 100644 --- a/folly/Memory.h +++ b/folly/Memory.h @@ -171,7 +171,9 @@ class SysAlloc { public: void* allocate(size_t size) { void* p = ::malloc(size); - if (!p) throw std::bad_alloc(); + if (!p) { + throw std::bad_alloc(); + } return p; } void deallocate(void* p) { @@ -340,7 +342,9 @@ class allocator_delete } void operator()(pointer p) const { - if (!p) return; + if (!p) { + return; + } const_cast(this)->destroy(p); const_cast(this)->deallocate(p, 1); } diff --git a/folly/MemoryMapping.cpp b/folly/MemoryMapping.cpp index 5165c073..30d6a1fe 100644 --- a/folly/MemoryMapping.cpp +++ b/folly/MemoryMapping.cpp @@ -177,8 +177,12 @@ void MemoryMapping::init(off_t offset, off_t length) { mapStart_ = nullptr; } else { int flags = options_.shared ? MAP_SHARED : MAP_PRIVATE; - if (anon) flags |= MAP_ANONYMOUS; - if (options_.prefault) flags |= MAP_POPULATE; + if (anon) { + flags |= MAP_ANONYMOUS; + } + if (options_.prefault) { + flags |= MAP_POPULATE; + } // The standard doesn't actually require PROT_NONE to be zero... int prot = PROT_NONE; @@ -280,7 +284,9 @@ bool MemoryMapping::mlock(LockMode lock) { } void MemoryMapping::munlock(bool dontneed) { - if (!locked_) return; + if (!locked_) { + return; + } size_t amountSucceeded = 0; if (!memOpInChunks( diff --git a/folly/RWSpinLock.h b/folly/RWSpinLock.h index 3cce0d90..8edd6b32 100644 --- a/folly/RWSpinLock.h +++ b/folly/RWSpinLock.h @@ -192,7 +192,9 @@ class RWSpinLock { void lock() { uint_fast32_t count = 0; while (!LIKELY(try_lock())) { - if (++count > 1000) std::this_thread::yield(); + if (++count > 1000) { + std::this_thread::yield(); + } } } @@ -206,7 +208,9 @@ class RWSpinLock { void lock_shared() { uint_fast32_t count = 0; while (!LIKELY(try_lock_shared())) { - if (++count > 1000) std::this_thread::yield(); + if (++count > 1000) { + std::this_thread::yield(); + } } } @@ -224,7 +228,9 @@ class RWSpinLock { void lock_upgrade() { uint_fast32_t count = 0; while (!try_lock_upgrade()) { - if (++count > 1000) std::this_thread::yield(); + if (++count > 1000) { + std::this_thread::yield(); + } } } @@ -236,7 +242,9 @@ class RWSpinLock { void unlock_upgrade_and_lock() { int64_t count = 0; while (!try_unlock_upgrade_and_lock()) { - if (++count > 1000) std::this_thread::yield(); + if (++count > 1000) { + std::this_thread::yield(); + } } } @@ -306,7 +314,9 @@ class RWSpinLock { class ReadHolder { public: explicit ReadHolder(RWSpinLock* lock) : lock_(lock) { - if (lock_) lock_->lock_shared(); + if (lock_) { + lock_->lock_shared(); + } } explicit ReadHolder(RWSpinLock& lock) : lock_(&lock) { @@ -320,12 +330,16 @@ class RWSpinLock { // down-grade explicit ReadHolder(UpgradedHolder&& upgraded) : lock_(upgraded.lock_) { upgraded.lock_ = nullptr; - if (lock_) lock_->unlock_upgrade_and_lock_shared(); + if (lock_) { + lock_->unlock_upgrade_and_lock_shared(); + } } explicit ReadHolder(WriteHolder&& writer) : lock_(writer.lock_) { writer.lock_ = nullptr; - if (lock_) lock_->unlock_and_lock_shared(); + if (lock_) { + lock_->unlock_and_lock_shared(); + } } ReadHolder& operator=(ReadHolder&& other) { @@ -337,13 +351,23 @@ class RWSpinLock { ReadHolder(const ReadHolder& other) = delete; ReadHolder& operator=(const ReadHolder& other) = delete; - ~ReadHolder() { if (lock_) lock_->unlock_shared(); } + ~ReadHolder() { + if (lock_) { + lock_->unlock_shared(); + } + } void reset(RWSpinLock* lock = nullptr) { - if (lock == lock_) return; - if (lock_) lock_->unlock_shared(); + if (lock == lock_) { + return; + } + if (lock_) { + lock_->unlock_shared(); + } lock_ = lock; - if (lock_) lock_->lock_shared(); + if (lock_) { + lock_->lock_shared(); + } } void swap(ReadHolder* other) { @@ -359,7 +383,9 @@ class RWSpinLock { class UpgradedHolder { public: explicit UpgradedHolder(RWSpinLock* lock) : lock_(lock) { - if (lock_) lock_->lock_upgrade(); + if (lock_) { + lock_->lock_upgrade(); + } } explicit UpgradedHolder(RWSpinLock& lock) : lock_(&lock) { @@ -369,7 +395,9 @@ class RWSpinLock { explicit UpgradedHolder(WriteHolder&& writer) { lock_ = writer.lock_; writer.lock_ = nullptr; - if (lock_) lock_->unlock_and_lock_upgrade(); + if (lock_) { + lock_->unlock_and_lock_upgrade(); + } } UpgradedHolder(UpgradedHolder&& other) noexcept : lock_(other.lock_) { @@ -385,13 +413,23 @@ class RWSpinLock { UpgradedHolder(const UpgradedHolder& other) = delete; UpgradedHolder& operator =(const UpgradedHolder& other) = delete; - ~UpgradedHolder() { if (lock_) lock_->unlock_upgrade(); } + ~UpgradedHolder() { + if (lock_) { + lock_->unlock_upgrade(); + } + } void reset(RWSpinLock* lock = nullptr) { - if (lock == lock_) return; - if (lock_) lock_->unlock_upgrade(); + if (lock == lock_) { + return; + } + if (lock_) { + lock_->unlock_upgrade(); + } lock_ = lock; - if (lock_) lock_->lock_upgrade(); + if (lock_) { + lock_->lock_upgrade(); + } } void swap(UpgradedHolder* other) { @@ -408,7 +446,9 @@ class RWSpinLock { class WriteHolder { public: explicit WriteHolder(RWSpinLock* lock) : lock_(lock) { - if (lock_) lock_->lock(); + if (lock_) { + lock_->lock(); + } } explicit WriteHolder(RWSpinLock& lock) : lock_(&lock) { @@ -419,7 +459,9 @@ class RWSpinLock { explicit WriteHolder(UpgradedHolder&& upgraded) { lock_ = upgraded.lock_; upgraded.lock_ = nullptr; - if (lock_) lock_->unlock_upgrade_and_lock(); + if (lock_) { + lock_->unlock_upgrade_and_lock(); + } } WriteHolder(WriteHolder&& other) noexcept : lock_(other.lock_) { @@ -435,13 +477,23 @@ class RWSpinLock { WriteHolder(const WriteHolder& other) = delete; WriteHolder& operator =(const WriteHolder& other) = delete; - ~WriteHolder () { if (lock_) lock_->unlock(); } + ~WriteHolder() { + if (lock_) { + lock_->unlock(); + } + } void reset(RWSpinLock* lock = nullptr) { - if (lock == lock_) return; - if (lock_) lock_->unlock(); + if (lock == lock_) { + return; + } + if (lock_) { + lock_->unlock(); + } lock_ = lock; - if (lock_) lock_->lock(); + if (lock_) { + lock_->lock(); + } } void swap(WriteHolder* other) { @@ -586,7 +638,9 @@ class RWTicketSpinLockT { bool try_lock() { RWTicket t; FullInt old = t.whole = load_acquire(&ticket.whole); - if (t.users != t.write) return false; + if (t.users != t.write) { + return false; + } ++t.users; return __sync_bool_compare_and_swap(&ticket.whole, old, t.whole); } @@ -607,7 +661,9 @@ class RWTicketSpinLockT { QuarterInt val = __sync_fetch_and_add(&ticket.users, 1); while (val != load_acquire(&ticket.write)) { asm_volatile_pause(); - if (UNLIKELY(++count > 1000)) std::this_thread::yield(); + if (UNLIKELY(++count > 1000)) { + std::this_thread::yield(); + } } } @@ -656,7 +712,9 @@ class RWTicketSpinLockT { uint_fast32_t count = 0; while (!LIKELY(try_lock_shared())) { asm_volatile_pause(); - if (UNLIKELY((++count & 1023) == 0)) std::this_thread::yield(); + if (UNLIKELY((++count & 1023) == 0)) { + std::this_thread::yield(); + } } } @@ -690,11 +748,15 @@ class RWTicketSpinLockT { ReadHolder& operator=(ReadHolder const&) = delete; explicit ReadHolder(RWSpinLock* lock) : lock_(lock) { - if (lock_) lock_->lock_shared(); + if (lock_) { + lock_->lock_shared(); + } } explicit ReadHolder(RWSpinLock &lock) : lock_ (&lock) { - if (lock_) lock_->lock_shared(); + if (lock_) { + lock_->lock_shared(); + } } // atomically unlock the write-lock from writer and acquire the read-lock @@ -706,13 +768,19 @@ class RWTicketSpinLockT { } ~ReadHolder() { - if (lock_) lock_->unlock_shared(); + if (lock_) { + lock_->unlock_shared(); + } } void reset(RWSpinLock *lock = nullptr) { - if (lock_) lock_->unlock_shared(); + if (lock_) { + lock_->unlock_shared(); + } lock_ = lock; - if (lock_) lock_->lock_shared(); + if (lock_) { + lock_->lock_shared(); + } } void swap(ReadHolder *other) { @@ -729,21 +797,33 @@ class RWTicketSpinLockT { WriteHolder& operator=(WriteHolder const&) = delete; explicit WriteHolder(RWSpinLock* lock) : lock_(lock) { - if (lock_) lock_->lock(); + if (lock_) { + lock_->lock(); + } } explicit WriteHolder(RWSpinLock &lock) : lock_ (&lock) { - if (lock_) lock_->lock(); + if (lock_) { + lock_->lock(); + } } ~WriteHolder() { - if (lock_) lock_->unlock(); + if (lock_) { + lock_->unlock(); + } } void reset(RWSpinLock *lock = nullptr) { - if (lock == lock_) return; - if (lock_) lock_->unlock(); + if (lock == lock_) { + return; + } + if (lock_) { + lock_->unlock(); + } lock_ = lock; - if (lock_) lock_->lock(); + if (lock_) { + lock_->lock(); + } } void swap(WriteHolder *other) { diff --git a/folly/String-inl.h b/folly/String-inl.h index cfcbd00a..2ec534bf 100644 --- a/folly/String-inl.h +++ b/folly/String-inl.h @@ -507,14 +507,21 @@ void backslashify( if (hex_style) { hex_append = true; } else { - if (c == '\r') output += 'r'; - else if (c == '\n') output += 'n'; - else if (c == '\t') output += 't'; - else if (c == '\a') output += 'a'; - else if (c == '\b') output += 'b'; - else if (c == '\0') output += '0'; - else if (c == '\\') output += '\\'; - else { + if (c == '\r') { + output += 'r'; + } else if (c == '\n') { + output += 'n'; + } else if (c == '\t') { + output += 't'; + } else if (c == '\a') { + output += 'a'; + } else if (c == '\b') { + output += 'b'; + } else if (c == '\0') { + output += '0'; + } else if (c == '\\') { + output += '\\'; + } else { hex_append = true; } } @@ -576,7 +583,9 @@ void humanify(const String1& input, String2& output) { template bool hexlify(const InputString& input, OutputString& output, bool append_output) { - if (!append_output) output.clear(); + if (!append_output) { + output.clear(); + } static char hexValues[] = "0123456789abcdef"; auto j = output.size(); diff --git a/folly/Subprocess.cpp b/folly/Subprocess.cpp index bd59336e..c342a969 100644 --- a/folly/Subprocess.cpp +++ b/folly/Subprocess.cpp @@ -72,10 +72,18 @@ ProcessReturnCode& ProcessReturnCode::operator=(ProcessReturnCode&& p) } ProcessReturnCode::State ProcessReturnCode::state() const { - if (rawStatus_ == RV_NOT_STARTED) return NOT_STARTED; - if (rawStatus_ == RV_RUNNING) return RUNNING; - if (WIFEXITED(rawStatus_)) return EXITED; - if (WIFSIGNALED(rawStatus_)) return KILLED; + if (rawStatus_ == RV_NOT_STARTED) { + return NOT_STARTED; + } + if (rawStatus_ == RV_RUNNING) { + return RUNNING; + } + if (WIFEXITED(rawStatus_)) { + return EXITED; + } + if (WIFSIGNALED(rawStatus_)) { + return KILLED; + } assume_unreachable(); } @@ -185,7 +193,9 @@ Subprocess::Subprocess( if (argv.empty()) { throw std::invalid_argument("argv must not be empty"); } - if (!executable) executable = argv[0].c_str(); + if (!executable) { + executable = argv[0].c_str(); + } spawn(cloneStrings(argv), executable, options, env); } diff --git a/folly/Unicode.cpp b/folly/Unicode.cpp index b222fe6a..811e65c7 100644 --- a/folly/Unicode.cpp +++ b/folly/Unicode.cpp @@ -67,7 +67,9 @@ char32_t utf8ToCodePoint( auto skip = [&] { ++p; return U'\ufffd'; }; if (p >= e) { - if (skipOnError) return skip(); + if (skipOnError) { + return skip(); + } throw std::runtime_error("folly::utf8ToCodePoint empty/invalid string"); } @@ -88,7 +90,9 @@ char32_t utf8ToCodePoint( uint32_t d = fst; if ((fst & 0xC0) != 0xC0) { - if (skipOnError) return skip(); + if (skipOnError) { + return skip(); + } throw std::runtime_error(to("folly::utf8ToCodePoint i=0 d=", d)); } @@ -98,7 +102,9 @@ char32_t utf8ToCodePoint( unsigned char tmp = p[i]; if ((tmp & 0xC0) != 0x80) { - if (skipOnError) return skip(); + if (skipOnError) { + return skip(); + } throw std::runtime_error( to("folly::utf8ToCodePoint i=", i, " tmp=", (uint32_t)tmp)); } @@ -111,7 +117,9 @@ char32_t utf8ToCodePoint( // overlong, could have been encoded with i bytes if ((d & ~bitMask[i - 1]) == 0) { - if (skipOnError) return skip(); + if (skipOnError) { + return skip(); + } throw std::runtime_error( to("folly::utf8ToCodePoint i=", i, " d=", d)); } @@ -119,7 +127,9 @@ char32_t utf8ToCodePoint( // check for surrogates only needed for 3 bytes if (i == 2) { if ((d >= 0xD800 && d <= 0xDFFF) || d > 0x10FFFF) { - if (skipOnError) return skip(); + if (skipOnError) { + return skip(); + } throw std::runtime_error( to("folly::utf8ToCodePoint i=", i, " d=", d)); } @@ -130,7 +140,9 @@ char32_t utf8ToCodePoint( } } - if (skipOnError) return skip(); + if (skipOnError) { + return skip(); + } throw std::runtime_error("folly::utf8ToCodePoint encoding length maxed out"); } diff --git a/folly/Varint.h b/folly/Varint.h index 2f53dcf1..c28d7f72 100644 --- a/folly/Varint.h +++ b/folly/Varint.h @@ -136,16 +136,56 @@ inline Expected tryDecodeVarint(Range& data) { if (LIKELY(size_t(end - begin) >= kMaxVarintLength64)) { // fast path int64_t b; do { - b = *p++; val = (b & 0x7f) ; if (b >= 0) break; - b = *p++; val |= (b & 0x7f) << 7; if (b >= 0) break; - b = *p++; val |= (b & 0x7f) << 14; if (b >= 0) break; - b = *p++; val |= (b & 0x7f) << 21; if (b >= 0) break; - b = *p++; val |= (b & 0x7f) << 28; if (b >= 0) break; - b = *p++; val |= (b & 0x7f) << 35; if (b >= 0) break; - b = *p++; val |= (b & 0x7f) << 42; if (b >= 0) break; - b = *p++; val |= (b & 0x7f) << 49; if (b >= 0) break; - b = *p++; val |= (b & 0x7f) << 56; if (b >= 0) break; - b = *p++; val |= (b & 0x01) << 63; if (b >= 0) break; + b = *p++; + val = (b & 0x7f); + if (b >= 0) { + break; + } + b = *p++; + val |= (b & 0x7f) << 7; + if (b >= 0) { + break; + } + b = *p++; + val |= (b & 0x7f) << 14; + if (b >= 0) { + break; + } + b = *p++; + val |= (b & 0x7f) << 21; + if (b >= 0) { + break; + } + b = *p++; + val |= (b & 0x7f) << 28; + if (b >= 0) { + break; + } + b = *p++; + val |= (b & 0x7f) << 35; + if (b >= 0) { + break; + } + b = *p++; + val |= (b & 0x7f) << 42; + if (b >= 0) { + break; + } + b = *p++; + val |= (b & 0x7f) << 49; + if (b >= 0) { + break; + } + b = *p++; + val |= (b & 0x7f) << 56; + if (b >= 0) { + break; + } + b = *p++; + val |= (b & 0x01) << 63; + if (b >= 0) { + break; + } return makeUnexpected(DecodeVarintError::TooManyBytes); } while (false); } else { diff --git a/folly/concurrency/test/AtomicSharedPtrCounted.h b/folly/concurrency/test/AtomicSharedPtrCounted.h index 35ec7400..45287829 100644 --- a/folly/concurrency/test/AtomicSharedPtrCounted.h +++ b/folly/concurrency/test/AtomicSharedPtrCounted.h @@ -49,13 +49,15 @@ class counted_ptr : public counted_ptr_base { T* p_; counted_ptr() : p_(nullptr) {} counted_ptr(counted_shared_tag, T* p) : p_(p) { - if (p_) + if (p_) { counted_ptr_base::getRef(p_)->add_ref(); + } } counted_ptr(const counted_ptr& o) : p_(o.p_) { - if (p_) + if (p_) { counted_ptr_base::getRef(p_)->add_ref(); + } } counted_ptr& operator=(const counted_ptr& o) { if (p_ && counted_ptr_base::getRef(p_)->release_ref() == 1) { @@ -63,8 +65,9 @@ class counted_ptr : public counted_ptr_base { free(counted_ptr_base::getRef(p_)); } p_ = o.p_; - if (p_) + if (p_) { counted_ptr_base::getRef(p_)->add_ref(); + } return *this; } explicit counted_ptr(T* p) : p_(p) { diff --git a/folly/concurrency/test/CoreCachedSharedPtrTest.cpp b/folly/concurrency/test/CoreCachedSharedPtrTest.cpp index bd29427f..4cf94c24 100644 --- a/folly/concurrency/test/CoreCachedSharedPtrTest.cpp +++ b/folly/concurrency/test/CoreCachedSharedPtrTest.cpp @@ -65,9 +65,10 @@ void parallelRun(Operation op, size_t numThreads, size_t iters) { }); } - for (auto& t : threads) + for (auto& t : threads) { t.join(); } +} void benchmarkSharedPtrCopy(size_t numThreads, size_t iters) { auto p = std::make_shared(1); diff --git a/folly/dynamic.cpp b/folly/dynamic.cpp index 08e97472..842b7fb6 100644 --- a/folly/dynamic.cpp +++ b/folly/dynamic.cpp @@ -310,7 +310,9 @@ char const* dynamic::typeName(Type t) { void dynamic::destroy() noexcept { // This short-circuit speeds up some microbenchmarks. - if (type_ == NULLT) return; + if (type_ == NULLT) { + return; + } #define FB_X(T) detail::Destroy::destroy(getAddress()) FB_DYNAMIC_APPLY(type_, FB_X); diff --git a/folly/executors/test/ThreadPoolExecutorTest.cpp b/folly/executors/test/ThreadPoolExecutorTest.cpp index 66388f9b..40b4af15 100644 --- a/folly/executors/test/ThreadPoolExecutorTest.cpp +++ b/folly/executors/test/ThreadPoolExecutorTest.cpp @@ -490,15 +490,17 @@ TEST(ThreadPoolExecutorTest, BugD3527722) { std::thread producer1([&] { ++turn; - while (turn < 4) + while (turn < 4) { ; + } ++turn; q.add(SlowMover(true)); }); std::thread producer2([&] { ++turn; - while (turn < 5) + while (turn < 5) { ; + } q.add(SlowMover(false)); }); diff --git a/folly/experimental/EliasFanoCoding.h b/folly/experimental/EliasFanoCoding.h index 96ea7cd7..edfed096 100644 --- a/folly/experimental/EliasFanoCoding.h +++ b/folly/experimental/EliasFanoCoding.h @@ -606,8 +606,9 @@ class EliasFanoReader { if (kUnchecked || LIKELY(position() + n < size_)) { if (LIKELY(n < kLinearScanThreshold)) { - for (SizeType i = 0; i < n; ++i) + for (SizeType i = 0; i < n; ++i) { upper_.next(); + } } else { upper_.skip(n); } @@ -735,7 +736,9 @@ class EliasFanoReader { while (true) { value_ = readLowerPart(upper_.position()) | (upper_.value() << numLowerBits_); - if (LIKELY(value_ >= value)) break; + if (LIKELY(value_ >= value)) { + break; + } upper_.next(); } } diff --git a/folly/experimental/EventCount.h b/folly/experimental/EventCount.h index f2f806cb..1496b8b1 100644 --- a/folly/experimental/EventCount.h +++ b/folly/experimental/EventCount.h @@ -175,7 +175,9 @@ inline void EventCount::wait(Key key) noexcept { template void EventCount::await(Condition condition) { - if (condition()) return; // fast path + if (condition()) { + return; // fast path + } // condition() is the only thing that may throw, everything else is // noexcept, so we can hoist the try/catch block outside of the loop diff --git a/folly/experimental/flat_combining/test/FlatCombiningTestHelpers.h b/folly/experimental/flat_combining/test/FlatCombiningTestHelpers.h index 81007de7..e2aa684d 100644 --- a/folly/experimental/flat_combining/test/FlatCombiningTestHelpers.h +++ b/folly/experimental/flat_combining/test/FlatCombiningTestHelpers.h @@ -80,8 +80,9 @@ uint64_t fc_test( started.fetch_add(1); Rec* myrec = (combining && tc) ? ex.allocRec() : nullptr; uint64_t sum = 0; - while (!start.load()) + while (!start.load()) { ; + } if (!combining) { // no combining @@ -141,8 +142,9 @@ uint64_t fc_test( }); } - while (started.load() < nthreads) + while (started.load() < nthreads) { ; + } auto tbegin = std::chrono::steady_clock::now(); // begin time measurement diff --git a/folly/experimental/hazptr/bench/HazptrBench.h b/folly/experimental/hazptr/bench/HazptrBench.h index 1b62bc50..971a4ff0 100644 --- a/folly/experimental/hazptr/bench/HazptrBench.h +++ b/folly/experimental/hazptr/bench/HazptrBench.h @@ -43,14 +43,16 @@ inline uint64_t run_once( for (int tid = 0; tid < nthreads; ++tid) { threads[tid] = std::thread([&, tid] { started.fetch_add(1); - while (!start.load()) + while (!start.load()) { /* spin */; + } fn(tid); }); } - while (started.load() < nthreads) + while (started.load() < nthreads) { /* spin */; + } // begin time measurement auto tbegin = std::chrono::steady_clock::now(); diff --git a/folly/experimental/hazptr/example/LockFreeLIFO.h b/folly/experimental/hazptr/example/LockFreeLIFO.h index 7627c44f..22a00de8 100644 --- a/folly/experimental/hazptr/example/LockFreeLIFO.h +++ b/folly/experimental/hazptr/example/LockFreeLIFO.h @@ -49,7 +49,9 @@ class LockFreeLIFO { void push(T val) { DEBUG_PRINT(this); auto pnode = new Node(val, head_.load()); - while (!head_.compare_exchange_weak(pnode->next_, pnode)); + while (!head_.compare_exchange_weak(pnode->next_, pnode)) { + ; + } } bool pop(T& val) { @@ -57,12 +59,16 @@ class LockFreeLIFO { hazptr_holder hptr; Node* pnode = head_.load(); do { - if (pnode == nullptr) + if (pnode == nullptr) { return false; - if (!hptr.try_protect(pnode, head_)) + } + if (!hptr.try_protect(pnode, head_)) { continue; + } auto next = pnode->next_; - if (head_.compare_exchange_weak(pnode, next)) break; + if (head_.compare_exchange_weak(pnode, next)) { + break; + } } while (true); hptr.reset(); val = pnode->value_; diff --git a/folly/experimental/hazptr/example/SWMRList.h b/folly/experimental/hazptr/example/SWMRList.h index 20aa0e3b..17ed7ce9 100644 --- a/folly/experimental/hazptr/example/SWMRList.h +++ b/folly/experimental/hazptr/example/SWMRList.h @@ -58,7 +58,9 @@ class SWMRListSet { void locate_lower_bound(const T& v, std::atomic*& prev) const { auto curr = prev->load(std::memory_order_relaxed); while (curr) { - if (curr->elem_ >= v) break; + if (curr->elem_ >= v) { + break; + } prev = &(curr->next_); curr = curr->next_.load(std::memory_order_relaxed); } @@ -78,7 +80,9 @@ class SWMRListSet { auto prev = &head_; locate_lower_bound(v, prev); auto curr = prev->load(std::memory_order_relaxed); - if (curr && curr->elem_ == v) return false; + if (curr && curr->elem_ == v) { + return false; + } prev->store(new Node(std::move(v), curr)); return true; } @@ -87,7 +91,9 @@ class SWMRListSet { auto prev = &head_; locate_lower_bound(v, prev); auto curr = prev->load(std::memory_order_relaxed); - if (!curr || curr->elem_ != v) return false; + if (!curr || curr->elem_ != v) { + return false; + } Node *curr_next = curr->next_.load(); // Patch up the actual list... prev->store(curr_next, std::memory_order_release); @@ -108,11 +114,13 @@ class SWMRListSet { auto curr = prev->load(std::memory_order_acquire); while (true) { if (!curr) { return false; } - if (!hptr_curr->try_protect(curr, *prev)) + if (!hptr_curr->try_protect(curr, *prev)) { break; + } auto next = curr->next_.load(std::memory_order_acquire); - if (prev->load(std::memory_order_acquire) != curr) + if (prev->load(std::memory_order_acquire) != curr) { break; + } if (curr->elem_ == val) { return true; } else if (!(curr->elem_ < val)) { diff --git a/folly/experimental/hazptr/example/WideCAS.h b/folly/experimental/hazptr/example/WideCAS.h index 9a3ed278..8b4ce81a 100644 --- a/folly/experimental/hazptr/example/WideCAS.h +++ b/folly/experimental/hazptr/example/WideCAS.h @@ -53,7 +53,9 @@ class WideCAS { do { p = hptr.get_protected(p_); if (p->val_ != u) { delete n; return false; } - if (p_.compare_exchange_weak(p, n)) break; + if (p_.compare_exchange_weak(p, n)) { + break; + } } while (true); hptr.reset(); p->retire(); diff --git a/folly/experimental/hazptr/hazptr-impl.h b/folly/experimental/hazptr/hazptr-impl.h index 5250a5de..178bd9db 100644 --- a/folly/experimental/hazptr/hazptr-impl.h +++ b/folly/experimental/hazptr/hazptr-impl.h @@ -638,8 +638,9 @@ inline hazptr_rec* hazptr_domain::hazptrAcquire() { p->active_.store(true, std::memory_order_relaxed); p->next_ = hazptrs_.load(std::memory_order_acquire); while (!hazptrs_.compare_exchange_weak( - p->next_, p, std::memory_order_release, std::memory_order_acquire)) + p->next_, p, std::memory_order_release, std::memory_order_acquire)) { /* keep trying */; + } auto hcount = hcount_.fetch_add(1); DEBUG_PRINT(this << " " << p << " " << sizeof(hazptr_rec) << " " << hcount); return p; diff --git a/folly/experimental/test/CodingTestUtils.h b/folly/experimental/test/CodingTestUtils.h index ffbfd53e..19a556cf 100644 --- a/folly/experimental/test/CodingTestUtils.h +++ b/folly/experimental/test/CodingTestUtils.h @@ -351,7 +351,9 @@ void bmJump(const List& list, const std::vector& data, Reader reader(list); for (size_t i = 0, j = 0; i < iters; ++i, ++j) { - if (j == order.size()) j = 0; + if (j == order.size()) { + j = 0; + } reader.jump(order[j]); folly::doNotOptimizeAway(reader.value()); } @@ -365,7 +367,9 @@ void bmJumpTo(const List& list, const std::vector& data, Reader reader(list); for (size_t i = 0, j = 0; i < iters; ++i, ++j) { - if (j == order.size()) j = 0; + if (j == order.size()) { + j = 0; + } reader.jumpTo(data[order[j]]); folly::doNotOptimizeAway(reader.value()); } diff --git a/folly/experimental/test/FlatCombiningPriorityQueueTest.cpp b/folly/experimental/test/FlatCombiningPriorityQueueTest.cpp index cb21b809..05650a12 100644 --- a/folly/experimental/test/FlatCombiningPriorityQueueTest.cpp +++ b/folly/experimental/test/FlatCombiningPriorityQueueTest.cpp @@ -129,14 +129,16 @@ static uint64_t run_once(PriorityQueue& pq, const Func& fn) { for (uint32_t tid = 0; tid < nthreads; ++tid) { threads[tid] = std::thread([&, tid] { started.fetch_add(1); - while (!start.load()) + while (!start.load()) { /* nothing */; + } fn(tid); }); } - while (started.load() < nthreads) + while (started.load() < nthreads) { /* nothing */; + } auto tbegin = std::chrono::steady_clock::now(); // begin time measurement diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index 258c9f83..70a2c581 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -334,9 +334,10 @@ Try& SemiFuture::getTry() { template void SemiFuture::throwIfInvalid() const { - if (!core_) + if (!core_) { throwNoState(); } +} template Optional> SemiFuture::poll() { @@ -1269,7 +1270,9 @@ namespace detail { template void waitImpl(FutureType& f) { // short-circuit if there's nothing to do - if (f.isReady()) return; + if (f.isReady()) { + return; + } FutureBatonType baton; f.setCallback_([&](const Try& /* t */) { baton.post(); }); @@ -1302,8 +1305,9 @@ void waitViaImpl(Future& f, DrivableExecutor* e) { // Set callback so to ensure that the via executor has something on it // so that once the preceding future triggers this callback, drive will // always have a callback to satisfy it - if (f.isReady()) + if (f.isReady()) { return; + } f = f.via(e).then([](T&& t) { return std::move(t); }); while (!f.isReady()) { e->drive(); diff --git a/folly/futures/ManualExecutor.cpp b/folly/futures/ManualExecutor.cpp index b7e31654..50941d02 100644 --- a/folly/futures/ManualExecutor.cpp +++ b/folly/futures/ManualExecutor.cpp @@ -38,8 +38,9 @@ size_t ManualExecutor::run() { while (!scheduledFuncs_.empty()) { auto& sf = scheduledFuncs_.top(); - if (sf.time > now_) + if (sf.time > now_) { break; + } funcs_.emplace(sf.moveOutFunc()); scheduledFuncs_.pop(); } @@ -72,8 +73,9 @@ void ManualExecutor::wait() { while (true) { { std::lock_guard lock(lock_); - if (!funcs_.empty()) + if (!funcs_.empty()) { break; + } } sem_.wait(); diff --git a/folly/futures/ManualExecutor.h b/folly/futures/ManualExecutor.h index a45de257..028a4ce6 100644 --- a/folly/futures/ManualExecutor.h +++ b/folly/futures/ManualExecutor.h @@ -132,8 +132,9 @@ namespace folly { bool operator<(ScheduledFunc const& b) const { // Earlier-scheduled things must be *higher* priority // in the max-based std::priority_queue - if (time == b.time) + if (time == b.time) { return ordinal > b.ordinal; + } return time > b.time; } diff --git a/folly/futures/Promise-inl.h b/folly/futures/Promise-inl.h index 5fe4ed2c..7471228c 100644 --- a/folly/futures/Promise-inl.h +++ b/folly/futures/Promise-inl.h @@ -76,8 +76,9 @@ Promise::~Promise() { template void Promise::detach() { if (core_) { - if (!retrieved_) + if (!retrieved_) { core_->detachFuture(); + } core_->detachPromise(); core_ = nullptr; } diff --git a/folly/futures/test/Benchmark.cpp b/folly/futures/test/Benchmark.cpp index 770a830e..56f4f712 100644 --- a/folly/futures/test/Benchmark.cpp +++ b/folly/futures/test/Benchmark.cpp @@ -94,18 +94,23 @@ BENCHMARK(no_contention) { BENCHMARK_SUSPEND { folly::Baton<> b1, b2; - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } consumer = std::thread([&]{ b1.post(); - for (auto& f : futures) f.then(incr); + for (auto& f : futures) { + f.then(incr); + } }); consumer.join(); producer = std::thread([&]{ b2.post(); - for (auto& p : promises) p.setValue(42); + for (auto& p : promises) { + p.setValue(42); + } }); b1.wait(); @@ -125,8 +130,9 @@ BENCHMARK_RELATIVE(contention) { BENCHMARK_SUSPEND { folly::Baton<> b1, b2; - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } consumer = std::thread([&]{ b1.post(); diff --git a/folly/futures/test/CollectTest.cpp b/folly/futures/test/CollectTest.cpp index c01fadf4..59ba80ea 100644 --- a/folly/futures/test/CollectTest.cpp +++ b/folly/futures/test/CollectTest.cpp @@ -36,8 +36,9 @@ TEST(Collect, collectAll) { std::vector> promises(10); std::vector> futures; - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } auto allf = collectAll(futures); @@ -59,8 +60,9 @@ TEST(Collect, collectAll) { std::vector> promises(4); std::vector> futures; - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } auto allf = collectAll(futures); @@ -91,18 +93,20 @@ TEST(Collect, collectAll) { std::vector> promises(10); std::vector> futures; - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } - auto allf = collectAll(futures) - .then([](Try>>&& ts) { - for (auto& f : ts.value()) - f.value(); - }); + auto allf = collectAll(futures).then([](Try>>&& ts) { + for (auto& f : ts.value()) { + f.value(); + } + }); std::shuffle(promises.begin(), promises.end(), rng); - for (auto& p : promises) + for (auto& p : promises) { p.setValue(); + } EXPECT_TRUE(allf.isReady()); } } @@ -113,8 +117,9 @@ TEST(Collect, collect) { std::vector> promises(10); std::vector> futures; - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } auto allf = collect(futures); @@ -135,8 +140,9 @@ TEST(Collect, collect) { std::vector> promises(10); std::vector> futures; - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } auto allf = collect(futures); @@ -170,8 +176,9 @@ TEST(Collect, collect) { std::vector> promises(10); std::vector> futures; - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } auto allf = collect(futures); @@ -189,8 +196,9 @@ TEST(Collect, collect) { std::vector> promises(10); std::vector> futures; - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } auto allf = collect(futures); @@ -224,8 +232,9 @@ TEST(Collect, collect) { std::vector>> promises(10); std::vector>> futures; - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } collect(futures); } @@ -247,8 +256,9 @@ TEST(Collect, collectNotDefaultConstructible) { std::iota(indices.begin(), indices.end(), 0); std::shuffle(indices.begin(), indices.end(), rng); - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } auto allf = collect(futures); @@ -270,8 +280,9 @@ TEST(Collect, collectAny) { std::vector> promises(10); std::vector> futures; - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } for (auto& f : futures) { EXPECT_FALSE(f.isReady()); @@ -298,8 +309,9 @@ TEST(Collect, collectAny) { std::vector> promises(10); std::vector> futures; - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } for (auto& f : futures) { EXPECT_FALSE(f.isReady()); @@ -319,8 +331,9 @@ TEST(Collect, collectAny) { std::vector> promises(10); std::vector> futures; - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } auto anyf = collectAny(futures) .then([](std::pair> p) { @@ -403,8 +416,9 @@ TEST(Collect, collectAnyWithoutException) { TEST(Collect, alreadyCompleted) { { std::vector> fs; - for (int i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) { fs.push_back(makeFuture()); + } collectAll(fs) .then([&](std::vector> ts) { @@ -413,8 +427,9 @@ TEST(Collect, alreadyCompleted) { } { std::vector> fs; - for (int i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) { fs.push_back(makeFuture(i)); + } collectAny(fs) .then([&](std::pair> p) { @@ -555,8 +570,9 @@ TEST(Collect, collectN) { std::vector> promises(10); std::vector> futures; - for (auto& p : promises) + for (auto& p : promises) { futures.push_back(p.getFuture()); + } bool flag = false; size_t n = 3; @@ -564,8 +580,9 @@ TEST(Collect, collectN) { .then([&](std::vector>> v) { flag = true; EXPECT_EQ(n, v.size()); - for (auto& tt : v) + for (auto& tt : v) { EXPECT_TRUE(tt.second.hasValue()); + } }); promises[0].setValue(); @@ -586,16 +603,18 @@ TEST(Collect, smallVector) { { folly::small_vector> futures; - for (int i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) { futures.push_back(makeFuture()); + } auto anyf = collectAny(futures); } { folly::small_vector> futures; - for (int i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) { futures.push_back(makeFuture()); + } auto allf = collectAll(futures); } diff --git a/folly/futures/test/FSMTest.cpp b/folly/futures/test/FSMTest.cpp index 1178603f..0217eda5 100644 --- a/folly/futures/test/FSMTest.cpp +++ b/folly/futures/test/FSMTest.cpp @@ -39,12 +39,16 @@ TEST(FSM, example) { }; // keep retrying until success (like a cas) - while (!tryTransition()) ; + while (!tryTransition()) { + ; + } EXPECT_EQ(State::B, fsm.getState()); EXPECT_EQ(1, count); EXPECT_EQ(0, unprotectedCount); - while (!tryTransition()) ; + while (!tryTransition()) { + ; + } EXPECT_EQ(State::A, fsm.getState()); EXPECT_EQ(0, count); EXPECT_EQ(-1, unprotectedCount); diff --git a/folly/futures/test/ViaTest.cpp b/folly/futures/test/ViaTest.cpp index 1a530d37..79e6c9bf 100644 --- a/folly/futures/test/ViaTest.cpp +++ b/folly/futures/test/ViaTest.cpp @@ -50,8 +50,9 @@ struct ViaFixture : public testing::Test { { t = std::thread([=] { ManualWaiter eastWaiter(eastExecutor); - while (!done) + while (!done) { eastWaiter.drive(); + } }); } @@ -466,7 +467,9 @@ TEST(Via, viaRaces) { p.setValue(); }); - while (!done) x.run(); + while (!done) { + x.run(); + } t1.join(); t2.join(); } diff --git a/folly/gen/test/BaseTest.cpp b/folly/gen/test/BaseTest.cpp index 5d9075bd..0158b936 100644 --- a/folly/gen/test/BaseTest.cpp +++ b/folly/gen/test/BaseTest.cpp @@ -877,10 +877,12 @@ TEST(Gen, MapYielders) { | map([](int n) { return GENERATOR(int) { int i; - for (i = 1; i < n; ++i) + for (i = 1; i < n; ++i) { yield(i); - for (; i >= 1; --i) + } + for (; i >= 1; --i) { yield(i); + } }; }) | concat; diff --git a/folly/hash/test/SpookyHashV1Test.cpp b/folly/hash/test/SpookyHashV1Test.cpp index d5987f8e..4ff19605 100644 --- a/folly/hash/test/SpookyHashV1Test.cpp +++ b/folly/hash/test/SpookyHashV1Test.cpp @@ -60,8 +60,9 @@ public: { m_a = 0xdeadbeef; m_b = m_c = m_d = seed; - for (int i=0; i<20; ++i) - (void)Value(); + for (int i = 0; i < 20; ++i) { + (void)Value(); + } } private: @@ -447,10 +448,14 @@ void TestDeltas(int seed) for (int m=0; mprev(); return LIKELY(!buf->isSharedOne()) ? buf : nullptr; } diff --git a/folly/io/async/AsyncServerSocket.cpp b/folly/io/async/AsyncServerSocket.cpp index 72f29d0c..908a95b6 100644 --- a/folly/io/async/AsyncServerSocket.cpp +++ b/folly/io/async/AsyncServerSocket.cpp @@ -55,15 +55,17 @@ int setCloseOnExec(int fd, int value) { int old_flags = fcntl(fd, F_GETFD, 0); // If reading the flags failed, return error indication now - if (old_flags < 0) + if (old_flags < 0) { return -1; + } // Set just the flag we want to set int new_flags; - if (value != 0) + if (value != 0) { new_flags = old_flags | FD_CLOEXEC; - else + } else { new_flags = old_flags & ~FD_CLOEXEC; + } // Store modified flag word in the descriptor return fcntl(fd, F_SETFD, new_flags); diff --git a/folly/io/async/AsyncSocket.cpp b/folly/io/async/AsyncSocket.cpp index 991b225c..a6fbe6fe 100644 --- a/folly/io/async/AsyncSocket.cpp +++ b/folly/io/async/AsyncSocket.cpp @@ -2692,7 +2692,9 @@ void AsyncSocket::invalidState(WriteCallback* callback) { } void AsyncSocket::doClose() { - if (fd_ == -1) return; + if (fd_ == -1) { + return; + } if (const auto shutdownSocketSet = wShutdownSocketSet_.lock()) { shutdownSocketSet->close(fd_); } else { diff --git a/folly/io/async/test/EventBaseTest.cpp b/folly/io/async/test/EventBaseTest.cpp index 1353976e..5ffa8da4 100644 --- a/folly/io/async/test/EventBaseTest.cpp +++ b/folly/io/async/test/EventBaseTest.cpp @@ -1211,7 +1211,9 @@ TEST(EventBaseTest, RunInEventBaseThreadAndWait) { th.join(); } size_t sum = 0; - for (auto& atom : atoms) sum += *atom; + for (auto& atom : atoms) { + sum += *atom; + } EXPECT_EQ(c, sum); } diff --git a/folly/sorted_vector_types.h b/folly/sorted_vector_types.h index 54f3cc26..e05cabd0 100644 --- a/folly/sorted_vector_types.h +++ b/folly/sorted_vector_types.h @@ -107,8 +107,9 @@ namespace detail { template int distance_if_multipass(Iterator first, Iterator last) { typedef typename std::iterator_traits::iterator_category categ; - if (std::is_same::value) + if (std::is_same::value) { return -1; + } return std::distance(first, last); } @@ -345,15 +346,17 @@ class sorted_vector_set iterator find(const key_type& key) { iterator it = lower_bound(key); - if (it == end() || !key_comp()(key, *it)) + if (it == end() || !key_comp()(key, *it)) { return it; + } return end(); } const_iterator find(const key_type& key) const { const_iterator it = lower_bound(key); - if (it == end() || !key_comp()(key, *it)) + if (it == end() || !key_comp()(key, *it)) { return it; + } return end(); } @@ -599,15 +602,17 @@ class sorted_vector_map iterator find(const key_type& key) { iterator it = lower_bound(key); - if (it == end() || !key_comp()(key, it->first)) + if (it == end() || !key_comp()(key, it->first)) { return it; + } return end(); } const_iterator find(const key_type& key) const { const_iterator it = lower_bound(key); - if (it == end() || !key_comp()(key, it->first)) + if (it == end() || !key_comp()(key, it->first)) { return it; + } return end(); } diff --git a/folly/test/AHMIntStressTest.cpp b/folly/test/AHMIntStressTest.cpp index a0837ca4..5f577afa 100644 --- a/folly/test/AHMIntStressTest.cpp +++ b/folly/test/AHMIntStressTest.cpp @@ -119,5 +119,7 @@ TEST(AHMIntStressTest, Test) { }); } - for (auto& t : threads) t.join(); + for (auto& t : threads) { + t.join(); +} } diff --git a/folly/test/AtomicHashArrayTest.cpp b/folly/test/AtomicHashArrayTest.cpp index 780076a1..15e76879 100644 --- a/folly/test/AtomicHashArrayTest.cpp +++ b/folly/test/AtomicHashArrayTest.cpp @@ -74,7 +74,9 @@ class MmapAllocator { T *allocate(size_t n) { void *p = mmap(nullptr, n * sizeof(T), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (p == MAP_FAILED) throw std::bad_alloc(); + if (p == MAP_FAILED) { + throw std::bad_alloc(); + } return (T *)p; } @@ -264,7 +266,9 @@ struct EqTraits { struct HashTraits { size_t operator()(char* a) { size_t result = 0; - while (a[0] != 0) result += static_cast(*(a++)); + while (a[0] != 0) { + result += static_cast(*(a++)); + } return result; } size_t operator()(const char& a) { @@ -272,7 +276,9 @@ struct HashTraits { } size_t operator()(const StringPiece a) { size_t result = 0; - for (const auto& ch : a) result += static_cast(ch); + for (const auto& ch : a) { + result += static_cast(ch); + } return result; } }; diff --git a/folly/test/AtomicHashMapTest.cpp b/folly/test/AtomicHashMapTest.cpp index f204f8ff..e2bedea4 100644 --- a/folly/test/AtomicHashMapTest.cpp +++ b/folly/test/AtomicHashMapTest.cpp @@ -134,7 +134,9 @@ struct EqTraits { struct HashTraits { size_t operator()(const char* a) { size_t result = 0; - while (a[0] != 0) result += static_cast(*(a++)); + while (a[0] != 0) { + result += static_cast(*(a++)); + } return result; } size_t operator()(const char& a) { @@ -142,7 +144,9 @@ struct HashTraits { } size_t operator()(const StringPiece a) { size_t result = 0; - for (const auto& ch : a) result += static_cast(ch); + for (const auto& ch : a) { + result += static_cast(ch); + } return result; } }; @@ -619,7 +623,9 @@ void* testEraseEraseThread(void*) { int currentLevel; do { currentLevel = insertedLevel.load(std::memory_order_acquire); - if (currentLevel == kTestEraseInsertions) currentLevel += lag + 1; + if (currentLevel == kTestEraseInsertions) { + currentLevel += lag + 1; + } } while (currentLevel - lag < i); KeyT key = randomizeKey(i); @@ -673,7 +679,9 @@ auto atomicHashArrayInsertRaceArray = AHA::create(2, configRace); void* atomicHashArrayInsertRaceThread(void* /* j */) { AHA* arr = atomicHashArrayInsertRaceArray.get(); uintptr_t numInserted = 0; - while (!runThreadsCreatedAllThreads.load()); + while (!runThreadsCreatedAllThreads.load()) { + ; + } for (int i = 0; i < 2; i++) { if (arr->insert(RecordT(randomizeKey(i), 0)).first != arr->end()) { numInserted++; @@ -867,7 +875,9 @@ BENCHMARK(mt_ahm_miss, iters) { numOpsPerThread = iters / FLAGS_numThreads; runThreads([](void* jj) -> void* { int64_t j = (int64_t) jj; - while (!runThreadsCreatedAllThreads.load()); + while (!runThreadsCreatedAllThreads.load()) { + ; + } for (int i = 0; i < numOpsPerThread; ++i) { KeyT key = i + j * numOpsPerThread * 100; folly::doNotOptimizeAway(globalAHM->find(key) == globalAHM->end()); @@ -881,7 +891,9 @@ BENCHMARK(mt_qpahm_miss, iters) { numOpsPerThread = iters / FLAGS_numThreads; runThreads([](void* jj) -> void* { int64_t j = (int64_t) jj; - while (!runThreadsCreatedAllThreads.load()); + while (!runThreadsCreatedAllThreads.load()) { + ; + } for (int i = 0; i < numOpsPerThread; ++i) { KeyT key = i + j * numOpsPerThread * 100; folly::doNotOptimizeAway(globalQPAHM->find(key) == globalQPAHM->end()); @@ -911,7 +923,9 @@ BENCHMARK(mt_ahm_find_insert_mix, iters) { numOpsPerThread = iters / FLAGS_numThreads; runThreads([](void* jj) -> void* { int64_t j = (int64_t) jj; - while (!runThreadsCreatedAllThreads.load()); + while (!runThreadsCreatedAllThreads.load()) { + ; + } for (int i = 0; i < numOpsPerThread; ++i) { if (i % 128) { // ~1% insert mix KeyT key = randomizeKey(i + j * numOpsPerThread); @@ -931,7 +945,9 @@ BENCHMARK(mt_qpahm_find_insert_mix, iters) { numOpsPerThread = iters / FLAGS_numThreads; runThreads([](void* jj) -> void* { int64_t j = (int64_t) jj; - while (!runThreadsCreatedAllThreads.load()); + while (!runThreadsCreatedAllThreads.load()) { + ; + } for (int i = 0; i < numOpsPerThread; ++i) { if (i % 128) { // ~1% insert mix KeyT key = randomizeKey(i + j * numOpsPerThread); @@ -950,7 +966,9 @@ BENCHMARK(mt_aha_find, iters) { numOpsPerThread = iters / FLAGS_numThreads; runThreads([](void* jj) -> void* { int64_t j = (int64_t) jj; - while (!runThreadsCreatedAllThreads.load()); + while (!runThreadsCreatedAllThreads.load()) { + ; + } for (int i = 0; i < numOpsPerThread; ++i) { KeyT key = randomizeKey(i + j * numOpsPerThread); folly::doNotOptimizeAway(globalAHA->find(key)->second); @@ -964,7 +982,9 @@ BENCHMARK(mt_ahm_find, iters) { numOpsPerThread = iters / FLAGS_numThreads; runThreads([](void* jj) -> void* { int64_t j = (int64_t) jj; - while (!runThreadsCreatedAllThreads.load()); + while (!runThreadsCreatedAllThreads.load()) { + ; + } for (int i = 0; i < numOpsPerThread; ++i) { KeyT key = randomizeKey(i + j * numOpsPerThread); folly::doNotOptimizeAway(globalAHM->find(key)->second); @@ -978,7 +998,9 @@ BENCHMARK(mt_qpahm_find, iters) { numOpsPerThread = iters / FLAGS_numThreads; runThreads([](void* jj) -> void* { int64_t j = (int64_t) jj; - while (!runThreadsCreatedAllThreads.load()); + while (!runThreadsCreatedAllThreads.load()) { + ; + } for (int i = 0; i < numOpsPerThread; ++i) { KeyT key = randomizeKey(i + j * numOpsPerThread); folly::doNotOptimizeAway(globalQPAHM->find(key)->second); diff --git a/folly/test/ConcurrentSkipListBenchmark.cpp b/folly/test/ConcurrentSkipListBenchmark.cpp index cfe9aa98..09b9d17b 100644 --- a/folly/test/ConcurrentSkipListBenchmark.cpp +++ b/folly/test/ConcurrentSkipListBenchmark.cpp @@ -72,7 +72,9 @@ void BM_IterateOverSet(int iters, int size) { auto iter = a_set.begin(); for (int i = 0; i < iters; ++i) { sum += *iter++; - if (iter == a_set.end()) iter = a_set.begin(); + if (iter == a_set.end()) { + iter = a_set.begin(); + } } BENCHMARK_SUSPEND { // VLOG(20) << "sum = " << sum; @@ -92,7 +94,9 @@ void BM_IterateSkipList(int iters, int size) { auto iter = skipList.begin(); for (int i = 0; i < iters; ++i) { sum += *iter++; - if (iter == skipList.end()) iter = skipList.begin(); + if (iter == skipList.end()) { + iter = skipList.begin(); + } } BENCHMARK_SUSPEND { @@ -114,7 +118,9 @@ void BM_SetMerge(int iters, int size) { int64_t mergedSum = 0; FOR_EACH(it, a_set) { - if (b_set.find(*it) != b_set.end()) mergedSum += *it; + if (b_set.find(*it) != b_set.end()) { + mergedSum += *it; + } } BENCHMARK_SUSPEND { // VLOG(20) << mergedSum; @@ -137,7 +143,9 @@ void BM_CSLMergeLookup(int iters, int size) { SkipListType::Skipper skipper(skipList2); FOR_EACH(it, skipList) { - if (skipper.to(*it)) mergedSum += *it; + if (skipper.to(*it)) { + mergedSum += *it; + } } BENCHMARK_SUSPEND { @@ -347,7 +355,9 @@ class ConcurrentAccessData { for (int i = 0; i < FLAGS_num_sets; ++i) { locks_[i] = new RWSpinLock(); - if (i > 0) sets_[i] = sets_[0]; + if (i > 0) { + sets_[i] = sets_[0]; + } } // This requires knowledge of the C++ library internals. Only use it if we're diff --git a/folly/test/ConcurrentSkipListTest.cpp b/folly/test/ConcurrentSkipListTest.cpp index 35651eb5..671a8341 100644 --- a/folly/test/ConcurrentSkipListTest.cpp +++ b/folly/test/ConcurrentSkipListTest.cpp @@ -115,7 +115,9 @@ static void concurrentSkip(const vector *values, int64_t sum = 0; SkipListAccessor::Skipper skipper(skipList); FOR_EACH(it, *values) { - if (skipper.to(*it)) sum += *it; + if (skipper.to(*it)) { + sum += *it; + } } VLOG(20) << "sum = " << sum; } @@ -266,8 +268,12 @@ TEST(ConcurrentSkipList, TestStringType) { struct UniquePtrComp { bool operator ()( const std::unique_ptr &x, const std::unique_ptr &y) const { - if (!x) return false; - if (!y) return true; + if (!x) { + return false; + } + if (!y) { + return true; + } return *x < *y; } }; diff --git a/folly/test/FBStringTest.cpp b/folly/test/FBStringTest.cpp index 0d0c20fd..64343b40 100644 --- a/folly/test/FBStringTest.cpp +++ b/folly/test/FBStringTest.cpp @@ -143,12 +143,16 @@ template void clause11_21_4_2_h(String & test) { EXPECT_EQ(test, s2); // Constructor from other iterators std::list lst; - for (auto c : test) lst.push_back(c); + for (auto c : test) { + lst.push_back(c); + } String s3(lst.begin(), lst.end()); EXPECT_EQ(test, s3); // Constructor from wchar_t iterators std::list lst1; - for (auto c : test) lst1.push_back(c); + for (auto c : test) { + lst1.push_back(c); + } String s4(lst1.begin(), lst1.end()); EXPECT_EQ(test, s4); // Constructor from wchar_t pointers @@ -249,8 +253,11 @@ template void clause11_21_4_4(String & test) { // exercise empty string empty("empty"); string notempty("not empty"); - if (test.empty()) test = String(empty.begin(), empty.end()); - else test = String(notempty.begin(), notempty.end()); + if (test.empty()) { + test = String(empty.begin(), empty.end()); + } else { + test = String(notempty.begin(), notempty.end()); + } } template void clause11_21_4_5(String & test) { @@ -828,8 +835,11 @@ template void clause11_21_4_7_9_a(String & test) { String s; randomString(&s, maxString); int tristate = test.compare(s); - if (tristate > 0) tristate = 1; - else if (tristate < 0) tristate = 2; + if (tristate > 0) { + tristate = 1; + } else if (tristate < 0) { + tristate = 2; + } Num2String(test, tristate); } @@ -840,8 +850,11 @@ template void clause11_21_4_7_9_b(String & test) { random(0, test.size()), random(0, test.size()), s); - if (tristate > 0) tristate = 1; - else if (tristate < 0) tristate = 2; + if (tristate > 0) { + tristate = 1; + } else if (tristate < 0) { + tristate = 2; + } Num2String(test, tristate); } @@ -854,8 +867,11 @@ template void clause11_21_4_7_9_c(String & test) { str, random(0, str.size()), random(0, str.size())); - if (tristate > 0) tristate = 1; - else if (tristate < 0) tristate = 2; + if (tristate > 0) { + tristate = 1; + } else if (tristate < 0) { + tristate = 2; + } Num2String(test, tristate); } @@ -863,9 +879,12 @@ template void clause11_21_4_7_9_d(String & test) { String s; randomString(&s, maxString); int tristate = test.compare(s.c_str()); - if (tristate > 0) tristate = 1; - else if (tristate < 0) tristate = 2; - Num2String(test, tristate); + if (tristate > 0) { + tristate = 1; + } else if (tristate < 0) { + tristate = 2; + } + Num2String(test, tristate); } template void clause11_21_4_7_9_e(String & test) { @@ -876,8 +895,11 @@ template void clause11_21_4_7_9_e(String & test) { random(0, test.size()), str.c_str(), random(0, str.size())); - if (tristate > 0) tristate = 1; - else if (tristate < 0) tristate = 2; + if (tristate > 0) { + tristate = 1; + } else if (tristate < 0) { + tristate = 2; + } Num2String(test, tristate); } @@ -996,7 +1018,10 @@ TEST(FBString, testAllClauses) { void(*f_fbstring)(folly::fbstring&), void(*f_wfbstring)(folly::basic_fbstring&)) { do { - if (1) {} else EXPECT_TRUE(1) << "Testing clause " << clause; + if (1) { + } else { + EXPECT_TRUE(1) << "Testing clause " << clause; + } randomString(&r); c = r; EXPECT_EQ(c, r); @@ -1020,7 +1045,9 @@ TEST(FBString, testAllClauses) { auto mbv = std::vector(wret + 1); auto mb = mbv.data(); int ret = wcstombs(mb, wc.c_str(), wret + 1); - if (ret == wret) mb[wret] = '\0'; + if (ret == wret) { + mb[wret] = '\0'; + } const char *mc = c.c_str(); std::string one(mb); std::string two(mc); diff --git a/folly/test/FBStringTestBenchmarks.cpp.h b/folly/test/FBStringTestBenchmarks.cpp.h index d1c68784..90bb8312 100644 --- a/folly/test/FBStringTestBenchmarks.cpp.h +++ b/folly/test/FBStringTestBenchmarks.cpp.h @@ -62,7 +62,9 @@ BENCHMARK_PARAM(BENCHFUN(ctorFromArray), 32768); void BENCHFUN(ctorFromTwoPointers)(size_t iters, size_t arg) { /* library-local */ static STRING s; BENCHMARK_SUSPEND { - if (s.size() < arg) s.resize(arg); + if (s.size() < arg) { + s.resize(arg); + } } FOR_EACH_RANGE (i, 0, iters) { STRING s1(s.begin(), s.end()); diff --git a/folly/test/FBVectorTestBenchmarks.cpp.h b/folly/test/FBVectorTestBenchmarks.cpp.h index e5181e4b..d46405ea 100644 --- a/folly/test/FBVectorTestBenchmarks.cpp.h +++ b/folly/test/FBVectorTestBenchmarks.cpp.h @@ -73,7 +73,9 @@ TESTFUN(clause_23_3_6_1_11) { EXPECT_EQ(v.size(), lst.size() / 2); j = 0; FOR_EACH (i, lst) { - if (j == v.size()) break; + if (j == v.size()) { + break; + } EXPECT_EQ(v[j], *i); j++; } @@ -373,7 +375,9 @@ void BENCHFUN(erase)(int iters, int /* size */) { auto const obj1 = randomObject(); VECTOR v(random(0U, 100U), obj1); FOR_EACH_RANGE (i, 0, iters) { - if (v.empty()) continue; + if (v.empty()) { + continue; + } v.erase(v.begin()); } } diff --git a/folly/test/FixedStringTest.cpp b/folly/test/FixedStringTest.cpp index 121e94fe..437bd67c 100644 --- a/folly/test/FixedStringTest.cpp +++ b/folly/test/FixedStringTest.cpp @@ -641,8 +641,9 @@ constexpr std::size_t countSpacesReverse(folly::FixedString<50> s) { std::size_t count = 0u; auto i = s.rbegin(); for( ; i != s.rend(); ++i, --i, i++, i--, i+=1, i-=1, i+=1 ) { - if (' ' == *i) + if (' ' == *i) { ++count; + } } return count; } diff --git a/folly/test/ForeachTest.cpp b/folly/test/ForeachTest.cpp index ded3b721..48331668 100644 --- a/folly/test/ForeachTest.cpp +++ b/folly/test/ForeachTest.cpp @@ -439,7 +439,9 @@ TEST(Foreach, ForEachEnumerateBreak) { sumAA += aa; sumIter += *iter; ++numIterations; - if (aa == 1) break; + if (aa == 1) { + break; + } } EXPECT_EQ(sumAA, 1); // 0 + 1 EXPECT_EQ(sumIter, 3); // 1 + 2 diff --git a/folly/test/IndexedMemPoolTest.cpp b/folly/test/IndexedMemPoolTest.cpp index c15566b2..8bdd98e5 100644 --- a/folly/test/IndexedMemPoolTest.cpp +++ b/folly/test/IndexedMemPoolTest.cpp @@ -280,8 +280,9 @@ TEST(IndexedMemPool, construction_destruction) { for (auto i = 0; i < nthreads; ++i) { thr[i] = std::thread([&]() { started.fetch_add(1); - while (!start.load()) + while (!start.load()) { ; + } for (auto j = 0; j < count; ++j) { uint32_t idx = pool.allocIndex(); if (idx != 0) { @@ -291,8 +292,9 @@ TEST(IndexedMemPool, construction_destruction) { }); } - while (started.load() < nthreads) + while (started.load() < nthreads) { ; + } start.store(true); for (auto& t : thr) { diff --git a/folly/test/RWSpinLockTest.cpp b/folly/test/RWSpinLockTest.cpp index fb61572f..385f2d2b 100644 --- a/folly/test/RWSpinLockTest.cpp +++ b/folly/test/RWSpinLockTest.cpp @@ -228,7 +228,9 @@ TEST(RWSpinLock, concurrent_holder_test) { sleep(5); stop.store(true, std::memory_order_release); - for (auto& t : threads) t.join(); + for (auto& t : threads) { + t.join(); + } LOG(INFO) << "reads: " << reads.load(std::memory_order_acquire) << "; writes: " << writes.load(std::memory_order_acquire) diff --git a/folly/test/SynchronizedTestLib-inl.h b/folly/test/SynchronizedTestLib-inl.h index 33b91bef..48951a62 100644 --- a/folly/test/SynchronizedTestLib-inl.h +++ b/folly/test/SynchronizedTestLib-inl.h @@ -763,7 +763,7 @@ template void testTimedSynchronized() { v->push_back(2 * threadIdx); // Aaand test the TIMED_SYNCHRONIZED macro - for (;;) + for (;;) { TIMED_SYNCHRONIZED(5, lv, v) { if (lv) { // Sleep for a random time to ensure we trigger timeouts @@ -776,6 +776,7 @@ template void testTimedSynchronized() { ++(*numTimeouts.contextualLock()); } + } }; static const size_t numThreads = 100; diff --git a/folly/test/TraitsTest.cpp b/folly/test/TraitsTest.cpp index fa6b6637..1289a07e 100644 --- a/folly/test/TraitsTest.cpp +++ b/folly/test/TraitsTest.cpp @@ -183,7 +183,9 @@ TEST(Traits, int128) { template void testIsRelocatable(Args&&... args) { - if (!IsRelocatable::value) return; + if (!IsRelocatable::value) { + return; + } // We use placement new on zeroed memory to avoid garbage subsections char vsrc[sizeof(T)] = { 0 }; diff --git a/folly/test/sorted_vector_test.cpp b/folly/test/sorted_vector_test.cpp index 0dcd8d00..834ed4cb 100644 --- a/folly/test/sorted_vector_test.cpp +++ b/folly/test/sorted_vector_test.cpp @@ -39,8 +39,9 @@ template void check_invariant(Container& c) { auto it = c.begin(); auto end = c.end(); - if (it == end) + if (it == end) { return; + } auto prev = it; ++it; for (; it != end; ++it, ++prev) { @@ -267,13 +268,15 @@ TEST(SortedVectorTypes, InitializerLists) { TEST(SortedVectorTypes, CustomCompare) { sorted_vector_set > s; - for (int i = 0; i < 200; ++i) + for (int i = 0; i < 200; ++i) { s.insert(i); + } check_invariant(s); sorted_vector_map > m; - for (int i = 0; i < 200; ++i) + for (int i = 0; i < 200; ++i) { m[i] = 12.0; + } check_invariant(m); } diff --git a/folly/test/stl_tests/StlVectorTest.cpp b/folly/test/stl_tests/StlVectorTest.cpp index b107cd98..1bd3c966 100644 --- a/folly/test/stl_tests/StlVectorTest.cpp +++ b/folly/test/stl_tests/StlVectorTest.cpp @@ -1419,21 +1419,31 @@ void verifyAllocator(int ele, int cap) { // Master verifier template void verify(int extras) { - if (!is_arithmetic::value) + if (!is_arithmetic::value) { ASSERT_EQ(0 + extras, getTotal()) << "there exist Data but no vectors"; + } isSane(); - if (::testing::Test::HasFatalFailure()) return; - if (customAllocator::value) verifyAllocator(0, 0); + if (::testing::Test::HasFatalFailure()) { + return; + } + if (customAllocator::value) { + verifyAllocator(0, 0); + } } template void verify(int extras, const Vector& v) { verifyVector(v); - if (!is_arithmetic::value) + if (!is_arithmetic::value) { ASSERT_EQ(v.size() + extras, getTotal()) << "not all Data are in the vector"; + } isSane(); - if (::testing::Test::HasFatalFailure()) return; - if (customAllocator::value) verifyAllocator(v.size(), v.capacity()); + if (::testing::Test::HasFatalFailure()) { + return; + } + if (customAllocator::value) { + verifyAllocator(v.size(), v.capacity()); + } } template void verify(int extras, const Vector& v1, const Vector& v2) { @@ -1445,11 +1455,16 @@ void verify(int extras, const Vector& v1, const Vector& v2) { size += v2.size(); cap += v2.capacity(); } - if (!is_arithmetic::value) + if (!is_arithmetic::value) { ASSERT_EQ(size + extras, getTotal()) << "not all Data are in the vector(s)"; + } isSane(); - if (::testing::Test::HasFatalFailure()) return; - if (customAllocator::value) verifyAllocator(size, cap); + if (::testing::Test::HasFatalFailure()) { + return; + } + if (customAllocator::value) { + verifyAllocator(size, cap); + } } //============================================================================= @@ -1495,9 +1510,13 @@ class DataState { } bool operator==(const DataState& o) const { - if (size_ != o.size_) return false; + if (size_ != o.size_) { + return false; + } for (size_type i = 0; i < size_; ++i) { - if (data_[i] != o.data_[i]) return false; + if (data_[i] != o.data_[i]) { + return false; + } } return true; } @@ -2071,7 +2090,9 @@ STL_TEST("23.2.1-7", inputIteratorAllocConstruction, STL_TEST("23.2.1-7", ilAllocConstruction, is_arithmetic, m) { // gcc fail - if (Ticker::TicksLeft >= 0) return; + if (Ticker::TicksLeft >= 0) { + return; + } const auto& cm = m; @@ -2123,8 +2144,10 @@ STL_TEST("23.2.3 Table 100.1", nCopyConstruction, ASSERT_TRUE(Allocator() == u.get_allocator()); ASSERT_EQ(n, u.size()) << "Vector(n, t).size() != n" << endl; - for (const auto& val : u) ASSERT_EQ(convertToInt(t), convertToInt(val)) - << "not all elements of Vector(n, t) are equal to t"; + for (const auto& val : u) { + ASSERT_EQ(convertToInt(t), convertToInt(val)) + << "not all elements of Vector(n, t) are equal to t"; + } } STL_TEST("23.2.3 Table 100.2", forwardIteratorConstruction, @@ -2143,9 +2166,10 @@ STL_TEST("23.2.3 Table 100.2", forwardIteratorConstruction, ASSERT_LE(Counter::CountTotalOps, j-i); ASSERT_EQ(j - i, u.size()) << "u(i,j).size() != j-i"; - for (auto it = u.begin(); it != u.end(); ++it, ++i) + for (auto it = u.begin(); it != u.end(); ++it, ++i) { ASSERT_EQ(*i, convertToInt(*it)) << "u(i,j) constructed incorrectly"; } +} STL_TEST("23.2.3 Table 100.2", inputIteratorConstruction, is_move_constructible, i, j) { @@ -2162,16 +2186,19 @@ STL_TEST("23.2.3 Table 100.2", inputIteratorConstruction, ASSERT_TRUE(Allocator() == u.get_allocator()); ASSERT_EQ(j - i, u.size()) << "u(i,j).size() != j-i"; - for (auto it = u.begin(); it != u.end(); ++it, ++i) + for (auto it = u.begin(); it != u.end(); ++it, ++i) { ASSERT_EQ(*i, convertToInt(*it)) << "u(i,j) constructed incorrectly"; } +} STL_TEST("23.2.3 Table 100.3", ilConstruction, is_arithmetic) { // whitebox: ensure that Vector(il) is implemented in terms of // Vector(il.begin(), il.end()) // gcc fail - if (Ticker::TicksLeft >= 0) return; + if (Ticker::TicksLeft >= 0) { + return; + } Vector u = { 1, 4, 7 }; @@ -2179,9 +2206,10 @@ STL_TEST("23.2.3 Table 100.3", ilConstruction, is_arithmetic) { ASSERT_EQ(3, u.size()) << "u(il).size() fail"; int i = 1; auto it = u.begin(); - for (; it != u.end(); ++it, i += 3) + for (; it != u.end(); ++it, i += 3) { ASSERT_EQ(i, convertToInt(*it)) << "u(il) constructed incorrectly"; } +} STL_TEST("23.2.3 Table 100.4", ilAssignment, is_arithmetic, a) { @@ -2189,7 +2217,9 @@ STL_TEST("23.2.3 Table 100.4", ilAssignment, // assign(il.begin(), il.end()) // gcc fail - if (Ticker::TicksLeft >= 0) return; + if (Ticker::TicksLeft >= 0) { + return; + } auto am = a.get_allocator(); @@ -2201,9 +2231,10 @@ STL_TEST("23.2.3 Table 100.4", ilAssignment, ASSERT_EQ(3, a.size()) << "u(il).size() fail"; int i = 1; auto it = a.begin(); - for (; it != a.end(); ++it, i += 3) + for (; it != a.end(); ++it, i += 3) { ASSERT_EQ(i, convertToInt(*it)) << "u(il) constructed incorrectly"; } +} //---------------------------- // insert-and-erase subsection @@ -2255,7 +2286,9 @@ STL_TEST("23.2.3 Table 100.6", iteratorInsertion, STL_TEST("23.2.3 Table 100.7", iteratorInsertionRV, is_move_constructibleAndAssignable, a, p, t) { // rvalue-references cannot have their address checked for aliased inserts - if (a.data() <= addressof(t) && addressof(t) < a.data() + a.size()) return; + if (a.data() <= addressof(t) && addressof(t) < a.data() + a.size()) { + return; + } DataState dsa(a); int idx = distance(a.begin(), p); @@ -2360,7 +2393,9 @@ STL_TEST("23.2.3 Table 100.9", iteratorInsertionInputIterator, STL_TEST("23.2.3 Table 100.10", iteratorInsertIL, is_arithmetic, a, p) { // gcc fail - if (Ticker::TicksLeft >= 0) return; + if (Ticker::TicksLeft >= 0) { + return; + } // whitebox: ensure that insert(p, il) is implemented in terms of // insert(p, il.begin(), il.end()) @@ -2392,13 +2427,17 @@ void eraseCheck(Vector& a, DataState& dsa, int idx, int n) { int i = 0; auto it = a.begin(); for (; it != a.end(); ++it, ++i) { - if (i == idx) i += n; + if (i == idx) { + i += n; + } ASSERT_EQ(dsa[i], convertToInt(*it)); } } STL_TEST("23.2.3 Table 100.11", iteratorErase, is_move_assignable, a, p) { - if (p == a.end()) return; + if (p == a.end()) { + return; + } DataState dsa(a); int idx = distance(a.begin(), p); @@ -2413,7 +2452,9 @@ STL_TEST("23.2.3 Table 100.11", iteratorErase, is_move_assignable, a, p) { STL_TEST("23.2.3 Table 100.12", iteratorEraseRange, is_move_assignable, a, p, q) { - if (p == a.end()) return; + if (p == a.end()) { + return; + } DataState dsa(a); int idx = distance(a.begin(), p); @@ -2454,9 +2495,10 @@ STL_TEST("23.2.3 Table 100.14", assignRange, is_move_assignable, a, i, j) { ASSERT_TRUE(am == a.get_allocator()); ASSERT_EQ(distance(i, j), a.size()); - for (auto it = a.begin(); it != a.end(); ++it, ++i) + for (auto it = a.begin(); it != a.end(); ++it, ++i) { ASSERT_EQ(*i, convertToInt(*it)); } +} STL_TEST("23.2.3 Table 100.14", assignInputRange, is_move_constructibleAndAssignable, a, i, j) { @@ -2470,9 +2512,10 @@ STL_TEST("23.2.3 Table 100.14", assignInputRange, ASSERT_TRUE(am == a.get_allocator()); ASSERT_EQ(distance(i, j), a.size()); - for (auto it = a.begin(); it != a.end(); ++it, ++i) + for (auto it = a.begin(); it != a.end(); ++it, ++i) { ASSERT_EQ(*i, convertToInt(*it)); } +} STL_TEST("23.2.3 Table 100.15", assignIL, is_arithmetic, a) { @@ -2481,7 +2524,9 @@ STL_TEST("23.2.3 Table 100.15", assignIL, // assign(il.begin(), il.end()) // gcc fail - if (Ticker::TicksLeft >= 0) return; + if (Ticker::TicksLeft >= 0) { + return; + } auto am = a.get_allocator(); @@ -2492,9 +2537,10 @@ STL_TEST("23.2.3 Table 100.15", assignIL, int* i = ila; ASSERT_EQ(3, a.size()); - for (auto it = a.begin(); it != a.end(); ++it, ++i) + for (auto it = a.begin(); it != a.end(); ++it, ++i) { ASSERT_EQ(*i, convertToInt(*it)); } +} STL_TEST("23.2.3 Table 100.16", assignN, is_copy_constructibleAndAssignable, a, n, t) { @@ -2506,12 +2552,15 @@ STL_TEST("23.2.3 Table 100.16", assignN, ASSERT_TRUE(am == a.get_allocator()); ASSERT_EQ(n, a.size()); - for (auto it = a.begin(); it != a.end(); ++it) + for (auto it = a.begin(); it != a.end(); ++it) { ASSERT_EQ(tval, convertToInt(*it)); } +} STL_TEST("23.2.3 Table 101.1", front, is_destructible, a) { - if (a.empty()) return; + if (a.empty()) { + return; + } ASSERT_TRUE(addressof(a.front()) == a.data()); @@ -2525,7 +2574,9 @@ STL_TEST("23.2.3 Table 101.1", front, is_destructible, a) { } STL_TEST("23.2.3 Table 101.2", back, is_destructible, a) { - if (a.empty()) return; + if (a.empty()) { + return; + } ASSERT_TRUE(addressof(a.back()) == a.data() + a.size() - 1); @@ -2553,12 +2604,15 @@ STL_TEST("23.2.3 Table 101.4", emplaceBack, } ASSERT_TRUE(am == a.get_allocator()); - if (excess > 0) ASSERT_TRUE(a.data() == adata) << "unnecessary relocation"; + if (excess > 0) { + ASSERT_TRUE(a.data() == adata) << "unnecessary relocation"; + } ASSERT_EQ(dsa.size() + 1, a.size()); size_t i = 0; auto it = a.begin(); - for (; i < dsa.size(); ++i, ++it) + for (; i < dsa.size(); ++i, ++it) { ASSERT_EQ(dsa[i], convertToInt(*it)); + } ASSERT_EQ(44, convertToInt(a.back())); } @@ -2578,12 +2632,15 @@ STL_TEST("23.2.3 Table 101.7", pushBack, is_copy_constructible, a, t) { } ASSERT_TRUE(am == a.get_allocator()); - if (excess > 0) ASSERT_TRUE(a.data() == adata) << "unnecessary relocation"; + if (excess > 0) { + ASSERT_TRUE(a.data() == adata) << "unnecessary relocation"; + } ASSERT_EQ(dsa.size() + 1, a.size()); size_t i = 0; auto it = a.begin(); - for (; i < dsa.size(); ++i, ++it) + for (; i < dsa.size(); ++i, ++it) { ASSERT_EQ(dsa[i], convertToInt(*it)); + } ASSERT_EQ(tval, convertToInt(a.back())); } @@ -2603,17 +2660,22 @@ STL_TEST("23.2.3 Table 101.8", pushBackRV, } ASSERT_TRUE(am == a.get_allocator()); - if (excess > 0) ASSERT_TRUE(a.data() == adata) << "unnecessary relocation"; + if (excess > 0) { + ASSERT_TRUE(a.data() == adata) << "unnecessary relocation"; + } ASSERT_EQ(dsa.size() + 1, a.size()); size_t i = 0; auto it = a.begin(); - for (; i < dsa.size(); ++i, ++it) + for (; i < dsa.size(); ++i, ++it) { ASSERT_EQ(dsa[i], convertToInt(*it)); + } ASSERT_EQ(tval, convertToInt(a.back())); } STL_TEST("23.2.3 Table 100.10", popBack, is_destructible, a) { - if (a.empty()) return; + if (a.empty()) { + return; + } DataState dsa(a); auto am = a.get_allocator(); @@ -2624,14 +2686,16 @@ STL_TEST("23.2.3 Table 100.10", popBack, is_destructible, a) { ASSERT_EQ(dsa.size() - 1, a.size()); size_t i = 0; auto it = a.begin(); - for (; it != a.end(); ++it, ++i) + for (; it != a.end(); ++it, ++i) { ASSERT_EQ(dsa[i], convertToInt(*it)); } +} STL_TEST("23.2.3 Table 100.11", operatorBrace, is_destructible, a) { const auto& ca = a; - for (size_t i = 0; i < ca.size(); ++i) + for (size_t i = 0; i < ca.size(); ++i) { ASSERT_TRUE(addressof(ca[i]) == ca.data()+i); + } ASSERT_EQ(0, Counter::CountTotalOps); @@ -2642,8 +2706,9 @@ STL_TEST("23.2.3 Table 100.11", operatorBrace, is_destructible, a) { STL_TEST("23.2.3 Table 100.12", at, is_destructible, a) { const auto& ca = a; - for (size_t i = 0; i < ca.size(); ++i) + for (size_t i = 0; i < ca.size(); ++i) { ASSERT_TRUE(addressof(ca.at(i)) == ca.data()+i); + } ASSERT_EQ(0, Counter::CountTotalOps); @@ -2710,7 +2775,9 @@ STL_TEST("23.3.6.3", reserve, is_move_constructible, a, n) { STL_TEST("23.3.6.3", lengthError, is_move_constructible) { auto mx = Vector().max_size(); auto big = mx+1; - if (mx >= big) return; // max_size is the biggest size_type; overflowed + if (mx >= big) { + return; // max_size is the biggest size_type; overflowed + } Vector u; try {