summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorMatt Cotter <matt.cotter@mongodb.com>2016-09-08 17:24:07 -0400
committerMatt Cotter <matt.cotter@mongodb.com>2016-09-09 13:22:25 -0400
commit2bd286acef2fdb035f1d45253f6e6e4c24a2dc04 (patch)
tree13943305b07a3e368ca48d5b1520cfee02ce0b3f /src/mongo/db
parentae280145c3c3dc770884a68885e80a282e8d50fd (diff)
downloadmongo-2bd286acef2fdb035f1d45253f6e6e4c24a2dc04.tar.gz
SERVER-22973 use mongo macros for static assert
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/concurrency/fast_map_noalloc.h5
-rw-r--r--src/mongo/db/concurrency/lock_manager.cpp21
-rw-r--r--src/mongo/db/concurrency/lock_manager_defs.h6
-rw-r--r--src/mongo/db/dbmessage.h5
-rw-r--r--src/mongo/db/pipeline/document_internal.h4
-rw-r--r--src/mongo/db/pipeline/value.cpp6
-rw-r--r--src/mongo/db/pipeline/value.h3
-rw-r--r--src/mongo/db/pipeline/value_internal.h3
-rw-r--r--src/mongo/db/repl/member_state.h3
-rw-r--r--src/mongo/db/server_parameters.h7
-rw-r--r--src/mongo/db/sorter/sorter_test.cpp21
-rw-r--r--src/mongo/db/stats/snapshots.cpp3
-rw-r--r--src/mongo/db/storage/key_string.cpp8
-rw-r--r--src/mongo/db/storage/key_string.h6
-rw-r--r--src/mongo/db/storage/mmap_v1/aligned_builder.cpp3
-rw-r--r--src/mongo/db/storage/mmap_v1/btree/btree_ondisk.h13
-rw-r--r--src/mongo/db/storage/mmap_v1/catalog/hashtab.h3
-rw-r--r--src/mongo/db/storage/mmap_v1/catalog/namespace.cpp16
-rw-r--r--src/mongo/db/storage/mmap_v1/catalog/namespace_details.cpp3
-rw-r--r--src/mongo/db/storage/mmap_v1/catalog/namespace_details.h10
-rw-r--r--src/mongo/db/storage/mmap_v1/catalog/namespace_details_rsv1_metadata.cpp8
-rw-r--r--src/mongo/db/storage/mmap_v1/data_file.cpp12
-rw-r--r--src/mongo/db/storage/mmap_v1/dur.cpp7
-rw-r--r--src/mongo/db/storage/mmap_v1/dur_journal.cpp13
-rw-r--r--src/mongo/db/storage/mmap_v1/durable_mapped_file.h9
-rw-r--r--src/mongo/db/storage/mmap_v1/extent.cpp3
-rw-r--r--src/mongo/db/storage/mmap_v1/logfile.cpp4
-rw-r--r--src/mongo/db/storage/mmap_v1/record.h3
-rw-r--r--src/mongo/db/storage/mmap_v1/record_store_v1_base.cpp8
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp7
30 files changed, 107 insertions, 116 deletions
diff --git a/src/mongo/db/concurrency/fast_map_noalloc.h b/src/mongo/db/concurrency/fast_map_noalloc.h
index eef9f4ceebe..8d862d7ac89 100644
--- a/src/mongo/db/concurrency/fast_map_noalloc.h
+++ b/src/mongo/db/concurrency/fast_map_noalloc.h
@@ -28,6 +28,7 @@
#pragma once
+#include "mongo/base/static_assert.h"
#include "mongo/platform/unordered_map.h"
#include "mongo/util/assert_util.h"
@@ -233,8 +234,8 @@ public:
private:
// Empty and very large maps do not make sense since there will be no performance gain, so
// disallow them.
- static_assert(PreallocCount > 0, "PreallocCount > 0");
- static_assert(PreallocCount < 32, "PreallocCount < 32");
+ MONGO_STATIC_ASSERT(PreallocCount > 0);
+ MONGO_STATIC_ASSERT(PreallocCount < 32);
// Iterator accesses the map directly
friend class IteratorImpl<FastMapNoAlloc<KeyType, ValueType, PreallocCount>, ValueType>;
diff --git a/src/mongo/db/concurrency/lock_manager.cpp b/src/mongo/db/concurrency/lock_manager.cpp
index 6653f5d0288..eb4c4567ce1 100644
--- a/src/mongo/db/concurrency/lock_manager.cpp
+++ b/src/mongo/db/concurrency/lock_manager.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/concurrency/lock_manager.h"
#include "mongo/base/simple_string_data_comparator.h"
+#include "mongo/base/static_assert.h"
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/config.h"
#include "mongo/db/concurrency/locker.h"
@@ -72,8 +73,7 @@ static const int LockConflictsTable[] = {
const uint64_t intentModes = (1 << MODE_IS) | (1 << MODE_IX);
// Ensure we do not add new modes without updating the conflicts table
-static_assert((sizeof(LockConflictsTable) / sizeof(LockConflictsTable[0])) == LockModesCount,
- "(sizeof(LockConflictsTable) / sizeof(LockConflictsTable[0])) == LockModesCount");
+MONGO_STATIC_ASSERT((sizeof(LockConflictsTable) / sizeof(LockConflictsTable[0])) == LockModesCount);
/**
@@ -84,10 +84,9 @@ static const char* LockModeNames[] = {"NONE", "IS", "IX", "S", "X"};
static const char* LegacyLockModeNames[] = {"", "r", "w", "R", "W"};
// Ensure we do not add new modes without updating the names array
-static_assert((sizeof(LockModeNames) / sizeof(LockModeNames[0])) == LockModesCount,
- "(sizeof(LockModeNames) / sizeof(LockModeNames[0])) == LockModesCount");
-static_assert((sizeof(LegacyLockModeNames) / sizeof(LegacyLockModeNames[0])) == LockModesCount,
- "(sizeof(LegacyLockModeNames) / sizeof(LegacyLockModeNames[0])) == LockModesCount");
+MONGO_STATIC_ASSERT((sizeof(LockModeNames) / sizeof(LockModeNames[0])) == LockModesCount);
+MONGO_STATIC_ASSERT((sizeof(LegacyLockModeNames) / sizeof(LegacyLockModeNames[0])) ==
+ LockModesCount);
// Helper functions for the lock modes
bool conflicts(LockMode newMode, uint32_t existingModesMask) {
@@ -106,8 +105,8 @@ static const char* ResourceTypeNames[] = {
"Invalid", "Global", "MMAPV1Journal", "Database", "Collection", "Metadata", "Mutex"};
// Ensure we do not add new types without updating the names array
-static_assert((sizeof(ResourceTypeNames) / sizeof(ResourceTypeNames[0])) == ResourceTypesCount,
- "(sizeof(ResourceTypeNames) / sizeof(ResourceTypeNames[0])) == ResourceTypesCount");
+MONGO_STATIC_ASSERT((sizeof(ResourceTypeNames) / sizeof(ResourceTypeNames[0])) ==
+ ResourceTypesCount);
/**
@@ -118,10 +117,8 @@ static const char* LockRequestStatusNames[] = {
};
// Ensure we do not add new status types without updating the names array
-static_assert((sizeof(LockRequestStatusNames) / sizeof(LockRequestStatusNames[0])) ==
- LockRequest::StatusCount,
- "(sizeof(LockRequestStatusNames) / sizeof(LockRequestStatusNames[0])) == "
- "LockRequest::StatusCount");
+MONGO_STATIC_ASSERT((sizeof(LockRequestStatusNames) / sizeof(LockRequestStatusNames[0])) ==
+ LockRequest::StatusCount);
} // namespace
diff --git a/src/mongo/db/concurrency/lock_manager_defs.h b/src/mongo/db/concurrency/lock_manager_defs.h
index 9e1ec088041..8849816278c 100644
--- a/src/mongo/db/concurrency/lock_manager_defs.h
+++ b/src/mongo/db/concurrency/lock_manager_defs.h
@@ -32,6 +32,7 @@
#include <limits>
#include <string>
+#include "mongo/base/static_assert.h"
#include "mongo/base/string_data.h"
#include "mongo/config.h"
#include "mongo/platform/hash_namespace.h"
@@ -175,8 +176,7 @@ const char* resourceTypeName(ResourceType resourceType);
class ResourceId {
// We only use 3 bits for the resource type in the ResourceId hash
enum { resourceTypeBits = 3 };
- static_assert(ResourceTypesCount <= (1 << resourceTypeBits),
- "ResourceTypesCount <= (1 << resourceTypeBits)");
+ MONGO_STATIC_ASSERT(ResourceTypesCount <= (1 << resourceTypeBits));
public:
/**
@@ -240,7 +240,7 @@ private:
#ifndef MONGO_CONFIG_DEBUG_BUILD
// Treat the resource ids as 64-bit integers in release mode in order to ensure we do
// not spend too much time doing comparisons for hashing.
-static_assert(sizeof(ResourceId) == sizeof(uint64_t), "sizeof(ResourceId) == sizeof(uint64_t)");
+MONGO_STATIC_ASSERT(sizeof(ResourceId) == sizeof(uint64_t));
#endif
diff --git a/src/mongo/db/dbmessage.h b/src/mongo/db/dbmessage.h
index 01530edd641..63d3aaea350 100644
--- a/src/mongo/db/dbmessage.h
+++ b/src/mongo/db/dbmessage.h
@@ -30,6 +30,7 @@
#pragma once
+#include "mongo/base/static_assert.h"
#include "mongo/bson/bson_validate.h"
#include "mongo/client/constants.h"
#include "mongo/db/jsobj.h"
@@ -202,7 +203,7 @@ private:
class Value : public EncodedValueStorage<Layout, ConstView, View> {
public:
Value() {
- static_assert(sizeof(Value) == sizeof(Layout), "sizeof(Value) == sizeof(Layout)");
+ MONGO_STATIC_ASSERT(sizeof(Value) == sizeof(Layout));
}
Value(ZeroInitTag_t zit) : EncodedValueStorage<Layout, ConstView, View>(zit) {}
@@ -217,7 +218,7 @@ public:
*/
class DbMessage {
// Assume sizeof(int) == 4 bytes
- static_assert(sizeof(int) == 4, "sizeof(int) == 4");
+ MONGO_STATIC_ASSERT(sizeof(int) == 4);
public:
// Note: DbMessage constructor reads the first 4 bytes and stores it in reserved
diff --git a/src/mongo/db/pipeline/document_internal.h b/src/mongo/db/pipeline/document_internal.h
index 3ad0d1ee577..2fd3c78cf34 100644
--- a/src/mongo/db/pipeline/document_internal.h
+++ b/src/mongo/db/pipeline/document_internal.h
@@ -33,6 +33,7 @@
#include <bitset>
#include <boost/intrusive_ptr.hpp>
+#include "mongo/base/static_assert.h"
#include "mongo/db/pipeline/value.h"
#include "mongo/util/intrusive_counter.h"
@@ -123,8 +124,7 @@ private:
};
// Real size is sizeof(ValueElement) + nameLen
#pragma pack()
-static_assert(sizeof(ValueElement) == (sizeof(Value) + sizeof(Position) + sizeof(int) + 1),
- "sizeof(ValueElement) == (sizeof(Value) + sizeof(Position) + sizeof(int) + 1)");
+MONGO_STATIC_ASSERT(sizeof(ValueElement) == (sizeof(Value) + sizeof(Position) + sizeof(int) + 1));
// This is an internal class for Document. See FieldIterator for the public version.
class DocumentStorageIterator {
diff --git a/src/mongo/db/pipeline/value.cpp b/src/mongo/db/pipeline/value.cpp
index 291cc205053..5eea4d314d1 100644
--- a/src/mongo/db/pipeline/value.cpp
+++ b/src/mongo/db/pipeline/value.cpp
@@ -181,8 +181,7 @@ Value::Value(const BSONElement& elem) : _storage(elem.type()) {
}
case jstOID:
- static_assert(sizeof(_storage.oid) == OID::kOIDSize,
- "sizeof(_storage.oid) == OID::kOIDSize");
+ MONGO_STATIC_ASSERT(sizeof(_storage.oid) == OID::kOIDSize);
memcpy(_storage.oid, elem.OID().view().view(), OID::kOIDSize);
break;
@@ -836,8 +835,7 @@ void Value::hash_combine(size_t& seed,
case bsonTimestamp:
case Date:
- static_assert(sizeof(_storage.dateValue) == sizeof(_storage.timestampValue),
- "sizeof(_storage.dateValue) == sizeof(_storage.timestampValue)");
+ MONGO_STATIC_ASSERT(sizeof(_storage.dateValue) == sizeof(_storage.timestampValue));
boost::hash_combine(seed, _storage.dateValue);
break;
diff --git a/src/mongo/db/pipeline/value.h b/src/mongo/db/pipeline/value.h
index b4dfc6a4943..544cce0d604 100644
--- a/src/mongo/db/pipeline/value.h
+++ b/src/mongo/db/pipeline/value.h
@@ -28,6 +28,7 @@
#pragma once
+#include "mongo/base/static_assert.h"
#include "mongo/base/string_data.h"
#include "mongo/db/pipeline/value_internal.h"
#include "mongo/platform/unordered_set.h"
@@ -334,7 +335,7 @@ private:
ValueStorage _storage;
friend class MutableValue; // gets and sets _storage.genericRCPtr
};
-static_assert(sizeof(Value) == 16, "sizeof(Value) == 16");
+MONGO_STATIC_ASSERT(sizeof(Value) == 16);
inline void swap(mongo::Value& lhs, mongo::Value& rhs) {
lhs.swap(rhs);
diff --git a/src/mongo/db/pipeline/value_internal.h b/src/mongo/db/pipeline/value_internal.h
index fe34b97e0a7..51d76e6cf73 100644
--- a/src/mongo/db/pipeline/value_internal.h
+++ b/src/mongo/db/pipeline/value_internal.h
@@ -32,6 +32,7 @@
#include <boost/config.hpp>
#include <boost/intrusive_ptr.hpp>
+#include "mongo/base/static_assert.h"
#include "mongo/bson/bsonmisc.h"
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/bsontypes.h"
@@ -358,6 +359,6 @@ public:
long long i64[2];
};
};
-static_assert(sizeof(ValueStorage) == 16, "sizeof(ValueStorage) == 16");
+MONGO_STATIC_ASSERT(sizeof(ValueStorage) == 16);
#pragma pack()
}
diff --git a/src/mongo/db/repl/member_state.h b/src/mongo/db/repl/member_state.h
index 44b8eb7976d..9a012bb8291 100644
--- a/src/mongo/db/repl/member_state.h
+++ b/src/mongo/db/repl/member_state.h
@@ -34,6 +34,7 @@
#include <type_traits>
#include "mongo/base/error_codes.h"
+#include "mongo/base/static_assert.h"
#include "mongo/base/status_with.h"
#include "mongo/util/mongoutils/str.h"
@@ -68,7 +69,7 @@ struct MemberState {
template <typename T>
static StatusWith<MemberState> create(T t) {
- static_assert(std::is_integral<T>::value, "T must be an integral type");
+ MONGO_STATIC_ASSERT_MSG(std::is_integral<T>::value, "T must be an integral type");
using UnderlyingType = std::underlying_type<MS>::type;
if (std::is_signed<T>::value && (t < 0))
return {ErrorCodes::BadValue, str::stream() << "MemberState cannot be negative"};
diff --git a/src/mongo/db/server_parameters.h b/src/mongo/db/server_parameters.h
index 9ce8d8b76be..e4b71c93d26 100644
--- a/src/mongo/db/server_parameters.h
+++ b/src/mongo/db/server_parameters.h
@@ -33,6 +33,7 @@
#include <map>
#include <string>
+#include "mongo/base/static_assert.h"
#include "mongo/base/status.h"
#include "mongo/db/jsobj.h"
#include "mongo/platform/atomic_proxy.h"
@@ -192,9 +193,9 @@ public:
template <typename T, ServerParameterType paramType>
class ExportedServerParameter : public ServerParameter {
public:
- static_assert(paramType == ServerParameterType::kStartupOnly ||
- is_safe_runtime_parameter_type<T>::value,
- "This type is not supported as a runtime server parameter.");
+ MONGO_STATIC_ASSERT_MSG(paramType == ServerParameterType::kStartupOnly ||
+ is_safe_runtime_parameter_type<T>::value,
+ "This type is not supported as a runtime server parameter.");
using storage_type = typename server_parameter_storage_type<T, paramType>::value_type;
diff --git a/src/mongo/db/sorter/sorter_test.cpp b/src/mongo/db/sorter/sorter_test.cpp
index 37bf118fe98..19171fb13ba 100644
--- a/src/mongo/db/sorter/sorter_test.cpp
+++ b/src/mongo/db/sorter/sorter_test.cpp
@@ -34,6 +34,7 @@
#include "mongo/base/data_type_endian.h"
#include "mongo/base/init.h"
+#include "mongo/base/static_assert.h"
#include "mongo/config.h"
#include "mongo/db/service_context.h"
#include "mongo/db/service_context_noop.h"
@@ -488,10 +489,8 @@ public:
SortOptions adjustSortOptions(SortOptions opts) {
// Make sure we use a reasonable number of files when we spill
- static_assert((NUM_ITEMS * sizeof(IWPair)) / MEM_LIMIT > 50,
- "(NUM_ITEMS * sizeof(IWPair)) / MEM_LIMIT > 50");
- static_assert((NUM_ITEMS * sizeof(IWPair)) / MEM_LIMIT < 500,
- "(NUM_ITEMS * sizeof(IWPair)) / MEM_LIMIT < 500");
+ MONGO_STATIC_ASSERT((NUM_ITEMS * sizeof(IWPair)) / MEM_LIMIT > 50);
+ MONGO_STATIC_ASSERT((NUM_ITEMS * sizeof(IWPair)) / MEM_LIMIT < 500);
return opts.MaxMemoryUsageBytes(MEM_LIMIT).ExtSortAllowed();
}
@@ -527,17 +526,13 @@ class LotsOfDataWithLimit : public LotsOfDataLittleMemory<Random> {
typedef LotsOfDataLittleMemory<Random> Parent;
SortOptions adjustSortOptions(SortOptions opts) {
// Make sure our tests will spill or not as desired
- static_assert(MEM_LIMIT / 2 > (100 * sizeof(IWPair)),
- "MEM_LIMIT / 2 > (100 * sizeof(IWPair))");
- static_assert(MEM_LIMIT < (5000 * sizeof(IWPair)), "MEM_LIMIT < (5000 * sizeof(IWPair))");
- static_assert(MEM_LIMIT * 2 > (5000 * sizeof(IWPair)),
- "MEM_LIMIT * 2 > (5000 * sizeof(IWPair))");
+ MONGO_STATIC_ASSERT(MEM_LIMIT / 2 > (100 * sizeof(IWPair)));
+ MONGO_STATIC_ASSERT(MEM_LIMIT < (5000 * sizeof(IWPair)));
+ MONGO_STATIC_ASSERT(MEM_LIMIT * 2 > (5000 * sizeof(IWPair)));
// Make sure we use a reasonable number of files when we spill
- static_assert((Parent::NUM_ITEMS * sizeof(IWPair)) / MEM_LIMIT > 100,
- "(Parent::NUM_ITEMS * sizeof(IWPair)) / MEM_LIMIT > 100");
- static_assert((Parent::NUM_ITEMS * sizeof(IWPair)) / MEM_LIMIT < 500,
- "(Parent::NUM_ITEMS * sizeof(IWPair)) / MEM_LIMIT < 500");
+ MONGO_STATIC_ASSERT((Parent::NUM_ITEMS * sizeof(IWPair)) / MEM_LIMIT > 100);
+ MONGO_STATIC_ASSERT((Parent::NUM_ITEMS * sizeof(IWPair)) / MEM_LIMIT < 500);
return opts.MaxMemoryUsageBytes(MEM_LIMIT).ExtSortAllowed().Limit(Limit);
}
diff --git a/src/mongo/db/stats/snapshots.cpp b/src/mongo/db/stats/snapshots.cpp
index a9d31319d2b..c1088f4d12f 100644
--- a/src/mongo/db/stats/snapshots.cpp
+++ b/src/mongo/db/stats/snapshots.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/stats/snapshots.h"
+#include "mongo/base/static_assert.h"
#include "mongo/db/client.h"
#include "mongo/db/clientcursor.h"
#include "mongo/db/service_context.h"
@@ -93,7 +94,7 @@ StatusWith<SnapshotDiff> Snapshots::computeDelta() {
}
// The following logic depends on there being exactly 2 stored snapshots
- static_assert(kNumSnapshots == 2, "kNumSnapshots == 2");
+ MONGO_STATIC_ASSERT(kNumSnapshots == 2);
// Current and previous napshot alternates between indexes 0 and 1
int currIdx = _loc;
diff --git a/src/mongo/db/storage/key_string.cpp b/src/mongo/db/storage/key_string.cpp
index 5c6adfc37c2..368ea038dd6 100644
--- a/src/mongo/db/storage/key_string.cpp
+++ b/src/mongo/db/storage/key_string.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/storage/key_string.h"
#include <cmath>
+#include <type_traits>
#include "mongo/base/data_view.h"
#include "mongo/platform/bits.h"
@@ -98,12 +99,11 @@ const uint8_t kNumericPositive6ByteInt = kNumeric + 18;
const uint8_t kNumericPositive7ByteInt = kNumeric + 19;
const uint8_t kNumericPositive8ByteInt = kNumeric + 20;
const uint8_t kNumericPositiveLargeMagnitude = kNumeric + 21; // >= 2**63 including +Inf
-static_assert(kNumericPositiveLargeMagnitude < kStringLike,
- "kNumericPositiveLargeMagnitude < kStringLike");
+MONGO_STATIC_ASSERT(kNumericPositiveLargeMagnitude < kStringLike);
const uint8_t kBoolFalse = kBool + 0;
const uint8_t kBoolTrue = kBool + 1;
-static_assert(kBoolTrue < kDate, "kBoolTrue < kDate");
+MONGO_STATIC_ASSERT(kBoolTrue < kDate);
size_t numBytesForInt(uint8_t ctype) {
if (ctype >= kNumericPositive1ByteInt) {
@@ -240,7 +240,7 @@ void memcpy_flipBits(void* dst, const void* src, size_t bytes) {
template <typename T>
T readType(BufReader* reader, bool inverted) {
- // TODO for C++11 to static_assert that T is integral
+ MONGO_STATIC_ASSERT(std::is_integral<T>::value);
T t = ConstDataView(static_cast<const char*>(reader->skip(sizeof(T)))).read<T>();
if (inverted)
return ~t;
diff --git a/src/mongo/db/storage/key_string.h b/src/mongo/db/storage/key_string.h
index 5b3d256f0d4..5884c707082 100644
--- a/src/mongo/db/storage/key_string.h
+++ b/src/mongo/db/storage/key_string.h
@@ -32,6 +32,7 @@
#include <limits>
+#include "mongo/base/static_assert.h"
#include "mongo/bson/bsonmisc.h"
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/bsonobjbuilder.h"
@@ -67,8 +68,9 @@ public:
static const uint32_t kBytesForTypeAndEmptyKey = 2;
static const uint32_t kMaxDecimalsPerKey =
kMaxKeyBytes / (sizeof(Decimal128::Value) + kBytesForTypeAndEmptyKey);
- static_assert(kMaxTypeBitsPerDecimal * kMaxDecimalsPerKey < kMaxBytesNeeded * 8UL,
- "encoding needs change to contain all type bits for worst case key");
+ MONGO_STATIC_ASSERT_MSG(
+ kMaxTypeBitsPerDecimal* kMaxDecimalsPerKey < kMaxBytesNeeded * 8UL,
+ "encoding needs change to contain all type bits for worst case key");
static const uint8_t kStoredDecimalExponentBits = 6;
static const uint32_t kStoredDecimalExponentMask = (1U << kStoredDecimalExponentBits) - 1;
diff --git a/src/mongo/db/storage/mmap_v1/aligned_builder.cpp b/src/mongo/db/storage/mmap_v1/aligned_builder.cpp
index 2af4891fe60..96e7ddd936e 100644
--- a/src/mongo/db/storage/mmap_v1/aligned_builder.cpp
+++ b/src/mongo/db/storage/mmap_v1/aligned_builder.cpp
@@ -32,6 +32,7 @@
#include "mongo/db/storage/mmap_v1/aligned_builder.h"
+#include "mongo/base/static_assert.h"
#include "mongo/util/debug_util.h"
#include "mongo/util/log.h"
@@ -45,7 +46,7 @@ AlignedBuilder::AlignedBuilder(unsigned initSize) {
uassert(13584, "out of memory AlignedBuilder", _p._allocationAddress);
}
-static_assert(sizeof(void*) == sizeof(size_t), "sizeof(void*) == sizeof(size_t)");
+MONGO_STATIC_ASSERT(sizeof(void*) == sizeof(size_t));
/** reset for a re-use. shrinks if > 128MB */
void AlignedBuilder::reset() {
diff --git a/src/mongo/db/storage/mmap_v1/btree/btree_ondisk.h b/src/mongo/db/storage/mmap_v1/btree/btree_ondisk.h
index 26c99cd50cb..9be2f947772 100644
--- a/src/mongo/db/storage/mmap_v1/btree/btree_ondisk.h
+++ b/src/mongo/db/storage/mmap_v1/btree/btree_ondisk.h
@@ -28,6 +28,7 @@
#pragma once
+#include "mongo/base/static_assert.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/storage/mmap_v1/btree/key.h"
#include "mongo/db/storage/mmap_v1/diskloc.h"
@@ -181,10 +182,8 @@ struct BtreeBucketV0 {
};
// BtreeBucketV0 is part of the on-disk format, so it should never be changed
-static_assert(sizeof(BtreeBucketV0) - sizeof(static_cast<BtreeBucketV0*>(NULL)->data) ==
- BtreeBucketV0::HeaderSize,
- "sizeof(BtreeBucketV0) - sizeof(static_cast<BtreeBucketV0*>(NULL)->data) == "
- "BtreeBucketV0::HeaderSize");
+MONGO_STATIC_ASSERT(sizeof(BtreeBucketV0) - sizeof(static_cast<BtreeBucketV0*>(NULL)->data) ==
+ BtreeBucketV0::HeaderSize);
/**
* A variant of DiskLoc Used by the V1 bucket type.
@@ -324,10 +323,8 @@ struct BtreeBucketV1 {
};
// BtreeBucketV1 is part of the on-disk format, so it should never be changed
-static_assert(sizeof(BtreeBucketV1) - sizeof(static_cast<BtreeBucketV1*>(NULL)->data) ==
- BtreeBucketV1::HeaderSize,
- "sizeof(BtreeBucketV1) - sizeof(static_cast<BtreeBucketV1*>(NULL)->data) == "
- "BtreeBucketV1::HeaderSize");
+MONGO_STATIC_ASSERT(sizeof(BtreeBucketV1) - sizeof(static_cast<BtreeBucketV1*>(NULL)->data) ==
+ BtreeBucketV1::HeaderSize);
enum Flags { Packed = 1 };
diff --git a/src/mongo/db/storage/mmap_v1/catalog/hashtab.h b/src/mongo/db/storage/mmap_v1/catalog/hashtab.h
index ecd0f8c4b4e..e22453b99db 100644
--- a/src/mongo/db/storage/mmap_v1/catalog/hashtab.h
+++ b/src/mongo/db/storage/mmap_v1/catalog/hashtab.h
@@ -28,6 +28,7 @@
#pragma once
+#include "mongo/base/static_assert.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/storage/mmap_v1/catalog/namespace.h"
#include "mongo/db/storage/mmap_v1/catalog/namespace_details.h"
@@ -116,7 +117,7 @@ private:
};
#pragma pack()
- static_assert(sizeof(Node) == 628, "sizeof(Node) == 628");
+ MONGO_STATIC_ASSERT(sizeof(Node) == 628);
int _find(const Namespace& k, bool& found) const;
diff --git a/src/mongo/db/storage/mmap_v1/catalog/namespace.cpp b/src/mongo/db/storage/mmap_v1/catalog/namespace.cpp
index b1e1d261dd6..a9ff70f8634 100644
--- a/src/mongo/db/storage/mmap_v1/catalog/namespace.cpp
+++ b/src/mongo/db/storage/mmap_v1/catalog/namespace.cpp
@@ -30,22 +30,18 @@
#include "mongo/platform/basic.h"
+#include "mongo/base/static_assert.h"
#include "mongo/db/storage/mmap_v1/catalog/namespace.h"
-
#include "mongo/db/namespace_string.h"
namespace mongo {
namespace {
-static_assert(sizeof(Namespace) == 128, "sizeof(Namespace) == 128");
-static_assert(Namespace::MaxNsLenWithNUL == MaxDatabaseNameLen,
- "Namespace::MaxNsLenWithNUL == MaxDatabaseNameLen");
-static_assert((int)Namespace::MaxNsLenWithNUL == (int)NamespaceString::MaxNsLenWithNUL,
- "(int)Namespace::MaxNsLenWithNUL == (int)NamespaceString::MaxNsLenWithNUL");
-static_assert((int)Namespace::MaxNsLen == (int)NamespaceString::MaxNsLen,
- "(int)Namespace::MaxNsLen == (int)NamespaceString::MaxNsLen");
+MONGO_STATIC_ASSERT(sizeof(Namespace) == 128);
+MONGO_STATIC_ASSERT(Namespace::MaxNsLenWithNUL == MaxDatabaseNameLen);
+MONGO_STATIC_ASSERT((int)Namespace::MaxNsLenWithNUL == (int)NamespaceString::MaxNsLenWithNUL);
+MONGO_STATIC_ASSERT((int)Namespace::MaxNsLen == (int)NamespaceString::MaxNsLen);
// Note the typo.
-static_assert((int)Namespace::MaxNsColletionLen == (int)NamespaceString::MaxNsCollectionLen,
- "(int)Namespace::MaxNsColletionLen == (int)NamespaceString::MaxNsCollectionLen");
+MONGO_STATIC_ASSERT((int)Namespace::MaxNsColletionLen == (int)NamespaceString::MaxNsCollectionLen);
}
}
diff --git a/src/mongo/db/storage/mmap_v1/catalog/namespace_details.cpp b/src/mongo/db/storage/mmap_v1/catalog/namespace_details.cpp
index a61a08261fb..d7f19c49f16 100644
--- a/src/mongo/db/storage/mmap_v1/catalog/namespace_details.cpp
+++ b/src/mongo/db/storage/mmap_v1/catalog/namespace_details.cpp
@@ -52,8 +52,7 @@
namespace mongo {
NamespaceDetails::NamespaceDetails(const DiskLoc& loc, bool capped) {
- static_assert(sizeof(NamespaceDetails::Extra) <= sizeof(NamespaceDetails),
- "sizeof(NamespaceDetails::Extra) <= sizeof(NamespaceDetails)");
+ MONGO_STATIC_ASSERT(sizeof(NamespaceDetails::Extra) <= sizeof(NamespaceDetails));
/* be sure to initialize new fields here -- doesn't default to zeroes the way we use it */
firstExtent = lastExtent = capExtent = loc;
diff --git a/src/mongo/db/storage/mmap_v1/catalog/namespace_details.h b/src/mongo/db/storage/mmap_v1/catalog/namespace_details.h
index 1da82400088..f1196bcd166 100644
--- a/src/mongo/db/storage/mmap_v1/catalog/namespace_details.h
+++ b/src/mongo/db/storage/mmap_v1/catalog/namespace_details.h
@@ -28,6 +28,7 @@
#pragma once
+#include "mongo/base/static_assert.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/storage/mmap_v1/catalog/index_details.h"
#include "mongo/db/storage/mmap_v1/catalog/namespace.h"
@@ -240,12 +241,11 @@ private:
/** Update cappedLastDelRecLastExtent() after capExtent changed in cappedTruncateAfter() */
void cappedTruncateLastDelUpdate();
- static_assert(NIndexesMax <= NIndexesBase + NIndexesExtra * 2,
- "NIndexesMax <= NIndexesBase + NIndexesExtra * 2");
- static_assert(NIndexesMax <= 64, "NIndexesMax <= 64"); // multiKey bits
- static_assert(sizeof(NamespaceDetails::Extra) == 496, "sizeof(NamespaceDetails::Extra) == 496");
+ MONGO_STATIC_ASSERT(NIndexesMax <= NIndexesBase + NIndexesExtra * 2);
+ MONGO_STATIC_ASSERT(NIndexesMax <= 64); // multiKey bits
+ MONGO_STATIC_ASSERT(sizeof(NamespaceDetails::Extra) == 496);
}; // NamespaceDetails
-static_assert(sizeof(NamespaceDetails) == 496, "sizeof(NamespaceDetails) == 496");
+MONGO_STATIC_ASSERT(sizeof(NamespaceDetails) == 496);
#pragma pack()
} // namespace mongo
diff --git a/src/mongo/db/storage/mmap_v1/catalog/namespace_details_rsv1_metadata.cpp b/src/mongo/db/storage/mmap_v1/catalog/namespace_details_rsv1_metadata.cpp
index 219f410283b..eaa3a1cf958 100644
--- a/src/mongo/db/storage/mmap_v1/catalog/namespace_details_rsv1_metadata.cpp
+++ b/src/mongo/db/storage/mmap_v1/catalog/namespace_details_rsv1_metadata.cpp
@@ -30,7 +30,7 @@
#include "mongo/db/storage/mmap_v1/catalog/namespace_details_rsv1_metadata.h"
-
+#include "mongo/base/static_assert.h"
#include "mongo/db/operation_context.h"
namespace mongo {
@@ -38,10 +38,8 @@ namespace mongo {
using std::unique_ptr;
using std::numeric_limits;
-static_assert(RecordStoreV1Base::Buckets ==
- NamespaceDetails::SmallBuckets + NamespaceDetails::LargeBuckets,
- "RecordStoreV1Base::Buckets == NamespaceDetails::SmallBuckets + "
- "NamespaceDetails::LargeBuckets");
+MONGO_STATIC_ASSERT(RecordStoreV1Base::Buckets ==
+ NamespaceDetails::SmallBuckets + NamespaceDetails::LargeBuckets);
NamespaceDetailsRSV1MetaData::NamespaceDetailsRSV1MetaData(StringData ns, NamespaceDetails* details)
: _ns(ns.toString()), _details(details) {}
diff --git a/src/mongo/db/storage/mmap_v1/data_file.cpp b/src/mongo/db/storage/mmap_v1/data_file.cpp
index b5fc8bf4d6c..c90ff1f74da 100644
--- a/src/mongo/db/storage/mmap_v1/data_file.cpp
+++ b/src/mongo/db/storage/mmap_v1/data_file.cpp
@@ -38,6 +38,7 @@
#include <utility>
#include <vector>
+#include "mongo/base/static_assert.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/storage/mmap_v1/dur.h"
#include "mongo/db/storage/mmap_v1/durable_mapped_file.h"
@@ -64,13 +65,10 @@ void data_file_check(void* _mb) {
} // namespace
-static_assert(DataFileHeader::HeaderSize == 8192, "DataFileHeader::HeaderSize == 8192");
-static_assert(sizeof(static_cast<DataFileHeader*>(NULL)->data) == 4,
- "sizeof(static_cast<DataFileHeader*>(NULL)->data) == 4");
-static_assert(sizeof(DataFileHeader) - sizeof(static_cast<DataFileHeader*>(NULL)->data) ==
- DataFileHeader::HeaderSize,
- "sizeof(DataFileHeader) - sizeof(static_cast<DataFileHeader*>(NULL)->data) == "
- "DataFileHeader::HeaderSize");
+MONGO_STATIC_ASSERT(DataFileHeader::HeaderSize == 8192);
+MONGO_STATIC_ASSERT(sizeof(static_cast<DataFileHeader*>(NULL)->data) == 4);
+MONGO_STATIC_ASSERT(sizeof(DataFileHeader) - sizeof(static_cast<DataFileHeader*>(NULL)->data) ==
+ DataFileHeader::HeaderSize);
int DataFile::maxSize() {
diff --git a/src/mongo/db/storage/mmap_v1/dur.cpp b/src/mongo/db/storage/mmap_v1/dur.cpp
index 480a6d34a89..1ed88c8d117 100644
--- a/src/mongo/db/storage/mmap_v1/dur.cpp
+++ b/src/mongo/db/storage/mmap_v1/dur.cpp
@@ -78,6 +78,7 @@
#include <iomanip>
#include <utility>
+#include "mongo/base/static_assert.h"
#include "mongo/db/client.h"
#include "mongo/db/commands/server_status.h"
#include "mongo/db/concurrency/lock_state.h"
@@ -149,10 +150,8 @@ unsigned remapFileToStartAt;
enum { DurStatsResetIntervalMillis = 3 * 1000 };
// Size sanity checks
-static_assert(UncommittedBytesLimit > BSONObjMaxInternalSize * 3,
- "UncommittedBytesLimit > BSONObjMaxInternalSize * 3");
-static_assert(sizeof(void*) == 4 || UncommittedBytesLimit > BSONObjMaxInternalSize * 6,
- "sizeof(void*) == 4 || UncommittedBytesLimit > BSONObjMaxInternalSize * 6");
+MONGO_STATIC_ASSERT(UncommittedBytesLimit > BSONObjMaxInternalSize * 3);
+MONGO_STATIC_ASSERT(sizeof(void*) == 4 || UncommittedBytesLimit > BSONObjMaxInternalSize * 6);
/**
diff --git a/src/mongo/db/storage/mmap_v1/dur_journal.cpp b/src/mongo/db/storage/mmap_v1/dur_journal.cpp
index e978e7e8e11..2d8e7b02fa6 100644
--- a/src/mongo/db/storage/mmap_v1/dur_journal.cpp
+++ b/src/mongo/db/storage/mmap_v1/dur_journal.cpp
@@ -38,6 +38,7 @@
#include <boost/filesystem/operations.hpp>
#include "mongo/base/init.h"
+#include "mongo/base/static_assert.h"
#include "mongo/config.h"
#include "mongo/db/client.h"
#include "mongo/db/storage/mmap_v1/aligned_builder.h"
@@ -96,12 +97,12 @@ MONGO_INITIALIZER(InitializeJournalingParams)(InitializerContext* context) {
return Status::OK();
}
-static_assert(sizeof(Checksum) == 16, "sizeof(Checksum) == 16");
-static_assert(sizeof(JHeader) == 8192, "sizeof(JHeader) == 8192");
-static_assert(sizeof(JSectHeader) == 20, "sizeof(JSectHeader) == 20");
-static_assert(sizeof(JSectFooter) == 32, "sizeof(JSectFooter) == 32");
-static_assert(sizeof(JEntry) == 12, "sizeof(JEntry) == 12");
-static_assert(sizeof(LSNFile) == 88, "sizeof(LSNFile) == 88");
+MONGO_STATIC_ASSERT(sizeof(Checksum) == 16);
+MONGO_STATIC_ASSERT(sizeof(JHeader) == 8192);
+MONGO_STATIC_ASSERT(sizeof(JSectHeader) == 20);
+MONGO_STATIC_ASSERT(sizeof(JSectFooter) == 32);
+MONGO_STATIC_ASSERT(sizeof(JEntry) == 12);
+MONGO_STATIC_ASSERT(sizeof(LSNFile) == 88);
bool usingPreallocate = false;
diff --git a/src/mongo/db/storage/mmap_v1/durable_mapped_file.h b/src/mongo/db/storage/mmap_v1/durable_mapped_file.h
index 404982b46e8..3175fa8fa73 100644
--- a/src/mongo/db/storage/mmap_v1/durable_mapped_file.h
+++ b/src/mongo/db/storage/mmap_v1/durable_mapped_file.h
@@ -31,6 +31,7 @@
#pragma once
+#include "mongo/base/static_assert.h"
#include "mongo/db/storage/mmap_v1/mmap.h"
#include "mongo/db/storage/paths.h"
#include "mongo/stdx/mutex.h"
@@ -159,13 +160,13 @@ public:
static const unsigned long long MaxWinMemory = 128ULL * 1024 * 1024 * 1024 * 1024;
// Make sure that the chunk memory covers the Max Windows user process VM space
- static_assert(MaxChunkMemory == MaxWinMemory,
- "Need a larger bitset to cover max process VM space");
+ MONGO_STATIC_ASSERT_MSG(MaxChunkMemory == MaxWinMemory,
+ "Need a larger bitset to cover max process VM space");
public:
MemoryMappedCOWBitset() {
- static_assert(MemoryMappedCOWBitset::MaxChunkBytes == sizeof(bits),
- "Validate our predicted bitset size is correct");
+ MONGO_STATIC_ASSERT_MSG(MemoryMappedCOWBitset::MaxChunkBytes == sizeof(bits),
+ "Validate our predicted bitset size is correct");
}
bool get(uintptr_t i) const {
diff --git a/src/mongo/db/storage/mmap_v1/extent.cpp b/src/mongo/db/storage/mmap_v1/extent.cpp
index fb134504f10..92dd07933b6 100644
--- a/src/mongo/db/storage/mmap_v1/extent.cpp
+++ b/src/mongo/db/storage/mmap_v1/extent.cpp
@@ -30,6 +30,7 @@
#include "mongo/db/storage/mmap_v1/extent.h"
+#include "mongo/base/static_assert.h"
#include "mongo/db/storage/mmap_v1/extent_manager.h"
#include "mongo/util/hex.h"
#include "mongo/util/mongoutils/str.h"
@@ -40,7 +41,7 @@ using std::iostream;
using std::string;
using std::vector;
-static_assert(sizeof(Extent) - 4 == 48 + 128, "sizeof(Extent) - 4 == 48 + 128");
+MONGO_STATIC_ASSERT(sizeof(Extent) - 4 == 48 + 128);
BSONObj Extent::dump() const {
return BSON("loc" << myLoc.toString() << "xnext" << xnext.toString() << "xprev"
diff --git a/src/mongo/db/storage/mmap_v1/logfile.cpp b/src/mongo/db/storage/mmap_v1/logfile.cpp
index 401d9b234a9..acf2db64d74 100644
--- a/src/mongo/db/storage/mmap_v1/logfile.cpp
+++ b/src/mongo/db/storage/mmap_v1/logfile.cpp
@@ -199,8 +199,8 @@ LogFile::~LogFile() {
void LogFile::truncate() {
verify(_fd >= 0);
- static_assert(sizeof(off_t) == 8, "sizeof(off_t) == 8"); // we don't want overflow here
- const off_t pos = lseek(_fd, 0, SEEK_CUR); // doesn't actually seek
+ MONGO_STATIC_ASSERT(sizeof(off_t) == 8); // we don't want overflow here
+ const off_t pos = lseek(_fd, 0, SEEK_CUR); // doesn't actually seek
if (ftruncate(_fd, pos) != 0) {
msgasserted(15873, "Couldn't truncate file: " + errnoWithDescription());
}
diff --git a/src/mongo/db/storage/mmap_v1/record.h b/src/mongo/db/storage/mmap_v1/record.h
index a8b63b13390..401808742a9 100644
--- a/src/mongo/db/storage/mmap_v1/record.h
+++ b/src/mongo/db/storage/mmap_v1/record.h
@@ -30,6 +30,7 @@
#pragma once
+#include "mongo/base/static_assert.h"
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/db/storage/mmap_v1/diskloc.h"
#include "mongo/db/storage/record_data.h"
@@ -175,6 +176,6 @@ private:
DiskLoc _nextDeleted;
};
-static_assert(16 == sizeof(DeletedRecord), "16 == sizeof(DeletedRecord)");
+MONGO_STATIC_ASSERT(16 == sizeof(DeletedRecord));
} // namespace mongo
diff --git a/src/mongo/db/storage/mmap_v1/record_store_v1_base.cpp b/src/mongo/db/storage/mmap_v1/record_store_v1_base.cpp
index fb3f101e172..6d9e263f7d6 100644
--- a/src/mongo/db/storage/mmap_v1/record_store_v1_base.cpp
+++ b/src/mongo/db/storage/mmap_v1/record_store_v1_base.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/storage/mmap_v1/record_store_v1_base.h"
+#include "mongo/base/static_assert.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/client.h"
#include "mongo/db/operation_context.h"
@@ -86,10 +87,9 @@ const int RecordStoreV1Base::bucketSizes[] = {
};
// If this fails, it means that bucketSizes doesn't have the correct number of entries.
-static_assert(sizeof(RecordStoreV1Base::bucketSizes) / sizeof(RecordStoreV1Base::bucketSizes[0]) ==
- RecordStoreV1Base::Buckets,
- "sizeof(RecordStoreV1Base::bucketSizes) / sizeof(RecordStoreV1Base::bucketSizes[0]) "
- "== RecordStoreV1Base::Buckets");
+MONGO_STATIC_ASSERT(sizeof(RecordStoreV1Base::bucketSizes) /
+ sizeof(RecordStoreV1Base::bucketSizes[0]) ==
+ RecordStoreV1Base::Buckets);
SavedCursorRegistry::~SavedCursorRegistry() {
for (SavedCursorSet::iterator it = _cursors.begin(); it != _cursors.end(); it++) {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index 4c83764fa3c..3dd326ba9ac 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -38,6 +38,7 @@
#include <wiredtiger.h>
#include "mongo/base/checked_cast.h"
+#include "mongo/base/static_assert.h"
#include "mongo/bson/util/builder.h"
#include "mongo/db/concurrency/locker.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
@@ -74,10 +75,8 @@ namespace {
static const int kMinimumRecordStoreVersion = 1;
static const int kCurrentRecordStoreVersion = 1; // New record stores use this by default.
static const int kMaximumRecordStoreVersion = 1;
-static_assert(kCurrentRecordStoreVersion >= kMinimumRecordStoreVersion,
- "kCurrentRecordStoreVersion >= kMinimumRecordStoreVersion");
-static_assert(kCurrentRecordStoreVersion <= kMaximumRecordStoreVersion,
- "kCurrentRecordStoreVersion <= kMaximumRecordStoreVersion");
+MONGO_STATIC_ASSERT(kCurrentRecordStoreVersion >= kMinimumRecordStoreVersion);
+MONGO_STATIC_ASSERT(kCurrentRecordStoreVersion <= kMaximumRecordStoreVersion);
bool shouldUseOplogHack(OperationContext* opCtx, const std::string& uri) {
StatusWith<BSONObj> appMetadata = WiredTigerUtil::getApplicationMetadata(opCtx, uri);