Commit de02e37f authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

switch from assert to FOLLY_SAFE_DCHECK

Summary:
assert(x) doesn't mark x as used in prod builds, causing problems
for builds that warn on unused variables and promote warnings to errors.
This diff changes assert calls to FOLLY_SAFE_DCHECK, which is better in
this regard.

Reviewed By: phoad, shixiao

Differential Revision: D7291084

fbshipit-source-id: 1ae48a271f30182ac8a1c2cf126af0e6b4fd0a25
parent 79778122
......@@ -32,6 +32,7 @@
#include <folly/Traits.h>
#include <folly/functional/ApplyTuple.h>
#include <folly/lang/Exception.h>
#include <folly/lang/SafeAssert.h>
#include <folly/container/detail/F14Policy.h>
#include <folly/container/detail/F14Table.h>
......@@ -294,7 +295,7 @@ class F14BasicMap {
template <class InputIt>
void initialInsert(InputIt first, InputIt last, std::size_t initialCapacity) {
assert(empty() && bucket_count() >= initialCapacity);
FOLLY_SAFE_DCHECK(empty() && bucket_count() >= initialCapacity, "");
// It's possible that there are a lot of duplicates in first..last and
// so we will oversize ourself. The common case, however, is that
......
......@@ -27,6 +27,8 @@
* @author Xiao Shi <xshi@fb.com>
*/
#include <folly/lang/SafeAssert.h>
#include <folly/container/detail/F14Policy.h>
#include <folly/container/detail/F14Table.h>
......@@ -269,7 +271,7 @@ class F14BasicSet {
template <class InputIt>
void initialInsert(InputIt first, InputIt last, std::size_t initialCapacity) {
assert(empty() && bucket_count() >= initialCapacity);
FOLLY_SAFE_DCHECK(empty() && bucket_count() >= initialCapacity, "");
// It's possible that there are a lot of duplicates in first..last and
// so we will oversize ourself. The common case, however, is that
......
......@@ -16,13 +16,13 @@
#pragma once
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <type_traits>
#include <folly/Portability.h>
#include <folly/lang/SafeAssert.h>
namespace folly {
namespace f14 {
......@@ -113,7 +113,7 @@ class TaggedPtr<T*> {
TaggedPtr(T* p, uint8_t e) noexcept
: raw_{(reinterpret_cast<uintptr_t>(p) << 8) | e} {
assert(ptr() == p);
FOLLY_SAFE_DCHECK(ptr() == p, "");
}
/* implicit */ TaggedPtr(std::nullptr_t) noexcept : raw_{0} {}
......@@ -137,7 +137,7 @@ class TaggedPtr<T*> {
void setPtr(T* p) {
*this = TaggedPtr{p, extra()};
assert(ptr() == p);
FOLLY_SAFE_DCHECK(ptr() == p, "");
}
uint8_t extra() const {
......
......@@ -18,6 +18,7 @@
#include <folly/container/detail/F14Table.h>
#include <folly/hash/Hash.h>
#include <folly/lang/SafeAssert.h>
#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
......@@ -222,7 +223,7 @@ struct BasePolicy
// prefetchBeforeCopy(), and prefetchBeforeDestroy(). if they don't
// override this method, because neither gcc nor clang can figure
// out that DenseMaskIter with an empty body can be elided.
assert(false);
FOLLY_SAFE_DCHECK(false, "should be disabled");
}
};
......@@ -858,7 +859,7 @@ class VectorContainerPolicy : public BasePolicy<
VectorContainerPolicy& operator=(VectorContainerPolicy const& rhs) {
if (this != &rhs) {
assert(values_ == nullptr);
FOLLY_SAFE_DCHECK(values_ == nullptr, "");
Super::operator=(rhs);
}
return *this;
......@@ -1006,7 +1007,7 @@ class VectorContainerPolicy : public BasePolicy<
VectorContainerPolicy const& rhs) {
Alloc& a = this->alloc();
assert(values_ != nullptr);
FOLLY_SAFE_DCHECK(values_ != nullptr, "");
Value const* src = std::addressof(rhs.values_[0]);
Value* dst = std::addressof(values_[0]);
......@@ -1038,16 +1039,18 @@ class VectorContainerPolicy : public BasePolicy<
std::size_t /*capacity*/,
VectorContainerPolicy const& /*rhs*/) {
// valueAtItemForCopy can be copied trivially, no failure should occur
assert(success);
FOLLY_SAFE_DCHECK(success, "");
}
ValuePtr beforeRehash(
std::size_t size,
std::size_t oldCapacity,
std::size_t newCapacity) {
assert(
FOLLY_SAFE_DCHECK(
size <= oldCapacity && ((values_ == nullptr) == (oldCapacity == 0)) &&
newCapacity > 0 && newCapacity <= (std::numeric_limits<Item>::max)());
newCapacity > 0 &&
newCapacity <= (std::numeric_limits<Item>::max)(),
"");
Alloc& a = this->alloc();
ValuePtr before = values_;
......@@ -1087,7 +1090,8 @@ class VectorContainerPolicy : public BasePolicy<
}
void beforeClear(std::size_t size, std::size_t capacity) {
assert(size <= capacity && ((values_ == nullptr) == (capacity == 0)));
FOLLY_SAFE_DCHECK(
size <= capacity && ((values_ == nullptr) == (capacity == 0)), "");
Alloc& a = this->alloc();
for (std::size_t i = 0; i < size; ++i) {
AllocTraits::destroy(a, std::addressof(values_[i]));
......@@ -1095,7 +1099,8 @@ class VectorContainerPolicy : public BasePolicy<
}
void beforeReset(std::size_t size, std::size_t capacity) {
assert(size <= capacity && ((values_ == nullptr) == (capacity == 0)));
FOLLY_SAFE_DCHECK(
size <= capacity && ((values_ == nullptr) == (capacity == 0)), "");
if (capacity > 0) {
beforeClear(size, capacity);
Alloc& a = this->alloc();
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment