diff options
author | Matt Cotter <matt.cotter@mongodb.com> | 2016-09-08 17:24:07 -0400 |
---|---|---|
committer | Matt Cotter <matt.cotter@mongodb.com> | 2016-09-09 13:22:25 -0400 |
commit | 2bd286acef2fdb035f1d45253f6e6e4c24a2dc04 (patch) | |
tree | 13943305b07a3e368ca48d5b1520cfee02ce0b3f | |
parent | ae280145c3c3dc770884a68885e80a282e8d50fd (diff) | |
download | mongo-2bd286acef2fdb035f1d45253f6e6e4c24a2dc04.tar.gz |
SERVER-22973 use mongo macros for static assert
53 files changed, 253 insertions, 199 deletions
diff --git a/src/mongo/base/data_type.h b/src/mongo/base/data_type.h index d25929e3601..caec3a1e6bf 100644 --- a/src/mongo/base/data_type.h +++ b/src/mongo/base/data_type.h @@ -33,6 +33,7 @@ #include <type_traits> #include "mongo/base/error_codes.h" +#include "mongo/base/static_assert.h" #include "mongo/base/status.h" #include "mongo/base/status_with.h" @@ -57,10 +58,10 @@ struct DataType { struct Handler { static void unsafeLoad(T* t, const char* ptr, size_t* advanced) { #if MONGO_HAVE_STD_IS_TRIVIALLY_COPYABLE - static_assert(std::is_trivially_copyable<T>::value, - "The generic DataType implementation requires values " - "to be trivially copyable. You may specialize the " - "template to use it with other types."); + MONGO_STATIC_ASSERT_MSG(std::is_trivially_copyable<T>::value, + "The generic DataType implementation requires values to be " + "trivially copyable. You may specialize the template to use it " + "with other types."); #endif if (t) { @@ -85,10 +86,10 @@ struct DataType { static void unsafeStore(const T& t, char* ptr, size_t* advanced) { #if MONGO_HAVE_STD_IS_TRIVIALLY_COPYABLE - static_assert(std::is_trivially_copyable<T>::value, - "The generic DataType implementation requires values " - "to be trivially copyable. You may specialize the " - "template to use it with other types."); + MONGO_STATIC_ASSERT_MSG(std::is_trivially_copyable<T>::value, + "The generic DataType implementation requires values to be " + "trivially copyable. You may specialize the template to use it " + "with other types."); #endif if (ptr) { diff --git a/src/mongo/base/encoded_value_storage_test.cpp b/src/mongo/base/encoded_value_storage_test.cpp index 465f416fda2..a0cd3f30de8 100644 --- a/src/mongo/base/encoded_value_storage_test.cpp +++ b/src/mongo/base/encoded_value_storage_test.cpp @@ -31,6 +31,7 @@ #include <cstring> #include "mongo/base/data_type_endian.h" +#include "mongo/base/static_assert.h" #include "mongo/platform/endian.h" #include "mongo/unittest/unittest.h" @@ -110,7 +111,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) {} diff --git a/src/mongo/base/secure_allocator.h b/src/mongo/base/secure_allocator.h index 416ff12ebfa..b22ccf771a5 100644 --- a/src/mongo/base/secure_allocator.h +++ b/src/mongo/base/secure_allocator.h @@ -36,6 +36,7 @@ #include <type_traits> #include <vector> +#include "mongo/base/static_assert.h" #include "mongo/stdx/type_traits.h" #include "mongo/util/assert_util.h" @@ -83,8 +84,8 @@ struct SecureAllocator { * */ #ifdef MONGO_CONFIG_HAVE_STD_IS_TRIVIALLY_COPYABLE - static_assert(std::is_trivially_copyable<T>::value, - "SecureAllocator can only be used with trivially copyable types"); + MONGO_STATIC_ASSERT_MSG(std::is_trivially_copyable<T>::value, + "SecureAllocator can only be used with trivially copyable types"); #endif // NOTE: The standard doesn't seem to require these, but libstdc++ diff --git a/src/mongo/base/static_assert.h b/src/mongo/base/static_assert.h new file mode 100644 index 00000000000..de8040264f6 --- /dev/null +++ b/src/mongo/base/static_assert.h @@ -0,0 +1,32 @@ +/* Copyright 2016 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects + * for all of the code used other than as permitted herein. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you do not + * wish to do so, delete this exception statement from your version. If you + * delete this exception statement from all source files in the program, + * then also delete it in the license file. + */ + +#pragma once + +#define MONGO_STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) + +#define MONGO_STATIC_ASSERT_MSG(...) static_assert(__VA_ARGS__) diff --git a/src/mongo/base/status_with.h b/src/mongo/base/status_with.h index 66880385ab4..29323861199 100644 --- a/src/mongo/base/status_with.h +++ b/src/mongo/base/status_with.h @@ -34,6 +34,7 @@ #include <type_traits> #include <utility> +#include "mongo/base/static_assert.h" #include "mongo/base/status.h" #define MONGO_INCLUDE_INVARIANT_H_WHITELISTED @@ -61,7 +62,8 @@ namespace mongo { */ template <typename T> class StatusWith { - static_assert(!(std::is_same<T, mongo::Status>::value), "StatusWith<Status> is banned."); + MONGO_STATIC_ASSERT_MSG(!(std::is_same<T, mongo::Status>::value), + "StatusWith<Status> is banned."); public: /** diff --git a/src/mongo/bson/mutable/document.cpp b/src/mongo/bson/mutable/document.cpp index ddf1f83281d..93ca13cc751 100644 --- a/src/mongo/bson/mutable/document.cpp +++ b/src/mongo/bson/mutable/document.cpp @@ -32,8 +32,10 @@ #include <cstdlib> #include <cstring> #include <limits> +#include <type_traits> #include <vector> +#include "mongo/base/static_assert.h" #include "mongo/bson/inline_decls.h" #include "mongo/bson/mutable/damage_vector.h" #include "mongo/util/debug_util.h" @@ -466,12 +468,12 @@ struct ElementRep { }; #pragma pack(pop) -static_assert(sizeof(ElementRep) == 32, "sizeof(ElementRep) == 32"); +MONGO_STATIC_ASSERT(sizeof(ElementRep) == 32); // We want ElementRep to be a POD so Document::Impl can grow the std::vector with // memmove. // -// TODO: C++11 static_assert(std::is_pod<ElementRep>::value); +MONGO_STATIC_ASSERT(std::is_pod<ElementRep>::value); // The ElementRep for the root element is always zero. const Element::RepIdx kRootRepIdx = Element::RepIdx(0); diff --git a/src/mongo/bson/oid.h b/src/mongo/bson/oid.h index 7debe105409..0dbf28a3277 100644 --- a/src/mongo/bson/oid.h +++ b/src/mongo/bson/oid.h @@ -32,6 +32,7 @@ #include <string> #include "mongo/base/data_view.h" +#include "mongo/base/static_assert.h" #include "mongo/bson/util/builder.h" #include "mongo/util/time_support.h" @@ -113,8 +114,8 @@ public: return o; } - static_assert(sizeof(int64_t) == kInstanceUniqueSize + kIncrementSize, - "size of term must be size of instance unique + increment"); + MONGO_STATIC_ASSERT_MSG(sizeof(int64_t) == kInstanceUniqueSize + kIncrementSize, + "size of term must be size of instance unique + increment"); // Return OID initialized with a 8 byte term id and max Timestamp. Used for ElectionID. static OID fromTerm(int64_t term) { diff --git a/src/mongo/bson/util/builder.h b/src/mongo/bson/util/builder.h index 258e63cf52d..1eb6f2378df 100644 --- a/src/mongo/bson/util/builder.h +++ b/src/mongo/bson/util/builder.h @@ -40,6 +40,7 @@ #include "mongo/base/data_type_endian.h" #include "mongo/base/data_view.h" #include "mongo/base/disallow_copying.h" +#include "mongo/base/static_assert.h" #include "mongo/base/string_data.h" #include "mongo/bson/bsontypes.h" #include "mongo/bson/inline_decls.h" @@ -194,7 +195,7 @@ public: } void appendUChar(unsigned char j) { - static_assert(CHAR_BIT == 8, "CHAR_BIT == 8"); + MONGO_STATIC_ASSERT(CHAR_BIT == 8); appendNumImpl(j); } void appendChar(char j) { @@ -204,11 +205,11 @@ public: appendNumImpl(j); } void appendNum(short j) { - static_assert(sizeof(short) == 2, "sizeof(short) == 2"); + MONGO_STATIC_ASSERT(sizeof(short) == 2); appendNumImpl(j); } void appendNum(int j) { - static_assert(sizeof(int) == 4, "sizeof(int) == 4"); + MONGO_STATIC_ASSERT(sizeof(int) == 4); appendNumImpl(j); } void appendNum(unsigned j) { @@ -219,11 +220,11 @@ public: void appendNum(bool j) = delete; void appendNum(double j) { - static_assert(sizeof(double) == 8, "sizeof(double) == 8"); + MONGO_STATIC_ASSERT(sizeof(double) == 8); appendNumImpl(j); } void appendNum(long long j) { - static_assert(sizeof(long long) == 8, "sizeof(long long) == 8"); + MONGO_STATIC_ASSERT(sizeof(long long) == 8); appendNumImpl(j); } 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); diff --git a/src/mongo/executor/network_interface_asio_command.cpp b/src/mongo/executor/network_interface_asio_command.cpp index f87b83736a4..4c981ff41e0 100644 --- a/src/mongo/executor/network_interface_asio_command.cpp +++ b/src/mongo/executor/network_interface_asio_command.cpp @@ -34,6 +34,7 @@ #include <type_traits> #include <utility> +#include "mongo/base/static_assert.h" #include "mongo/db/dbmessage.h" #include "mongo/db/jsobj.h" #include "mongo/executor/async_stream_interface.h" @@ -76,8 +77,9 @@ using IsNetworkHandler = template <typename Handler> void asyncSendMessage(AsyncStreamInterface& stream, Message* m, Handler&& handler) { - static_assert(IsNetworkHandler<Handler>::value, - "Handler passed to asyncSendMessage does not conform to NetworkHandler concept"); + MONGO_STATIC_ASSERT_MSG( + IsNetworkHandler<Handler>::value, + "Handler passed to asyncSendMessage does not conform to NetworkHandler concept"); m->header().setResponseToMsgId(0); m->header().setId(nextMessageId()); // TODO: Some day we may need to support vector messages. @@ -89,7 +91,7 @@ template <typename Handler> void asyncRecvMessageHeader(AsyncStreamInterface& stream, MSGHEADER::Value* header, Handler&& handler) { - static_assert( + MONGO_STATIC_ASSERT_MSG( IsNetworkHandler<Handler>::value, "Handler passed to asyncRecvMessageHeader does not conform to NetworkHandler concept"); stream.read(asio::buffer(header->view().view2ptr(), sizeof(decltype(*header))), @@ -101,7 +103,7 @@ void asyncRecvMessageBody(AsyncStreamInterface& stream, MSGHEADER::Value* header, Message* m, Handler&& handler) { - static_assert( + MONGO_STATIC_ASSERT_MSG( IsNetworkHandler<Handler>::value, "Handler passed to asyncRecvMessageBody does not conform to NetworkHandler concept"); // validate message length diff --git a/src/mongo/logger/log_component.cpp b/src/mongo/logger/log_component.cpp index 8b8db2e2c54..1599a05aaad 100644 --- a/src/mongo/logger/log_component.cpp +++ b/src/mongo/logger/log_component.cpp @@ -29,8 +29,8 @@ #include "mongo/logger/log_component.h" - #include "mongo/base/init.h" +#include "mongo/base/static_assert.h" #include "mongo/util/assert_util.h" namespace mongo { @@ -61,11 +61,11 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SetupDottedNames, MONGO_NO_PREREQUISITES) // Children always come after parent component. // This makes it unnecessary to compute children of each component // when setting/clearing log severities in LogComponentSettings. -#define DECLARE_LOG_COMPONENT_PARENT(CHILD, PARENT) \ - case (CHILD): \ - do { \ - static_assert(int(CHILD) > int(PARENT), "int(CHILD) > int(PARENT)"); \ - return (PARENT); \ +#define DECLARE_LOG_COMPONENT_PARENT(CHILD, PARENT) \ + case (CHILD): \ + do { \ + MONGO_STATIC_ASSERT(int(CHILD) > int(PARENT)); \ + return (PARENT); \ } while (0) LogComponent LogComponent::parent() const { diff --git a/src/mongo/platform/atomic_proxy.h b/src/mongo/platform/atomic_proxy.h index ae7960cb930..7f1dcb2061a 100644 --- a/src/mongo/platform/atomic_proxy.h +++ b/src/mongo/platform/atomic_proxy.h @@ -33,6 +33,7 @@ #include <cstring> #include <type_traits> +#include "mongo/base/static_assert.h" #include "mongo/config.h" namespace mongo { @@ -43,10 +44,12 @@ namespace mongo { */ template <typename T, typename BaseWordT> class AtomicProxy { - static_assert(sizeof(T) == sizeof(BaseWordT), "T and BaseWordT must have the same size"); - static_assert(std::is_integral<BaseWordT>::value, "BaseWordT must be an integral type"); + MONGO_STATIC_ASSERT_MSG(sizeof(T) == sizeof(BaseWordT), + "T and BaseWordT must have the same size"); + MONGO_STATIC_ASSERT_MSG(std::is_integral<BaseWordT>::value, + "BaseWordT must be an integral type"); #if MONGO_HAVE_STD_IS_TRIVIALLY_COPYABLE - static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable"); + MONGO_STATIC_ASSERT_MSG(std::is_trivially_copyable<T>::value, "T must be trivially copyable"); #endif public: using value_type = T; diff --git a/src/mongo/platform/atomic_word.h b/src/mongo/platform/atomic_word.h index f38763719a1..eb19496f0ba 100644 --- a/src/mongo/platform/atomic_word.h +++ b/src/mongo/platform/atomic_word.h @@ -30,6 +30,7 @@ #include <atomic> #include <type_traits> +#include "mongo/base/static_assert.h" namespace mongo { @@ -149,11 +150,11 @@ private: std::atomic<WordType> _value; // NOLINT }; -#define _ATOMIC_WORD_DECLARE(NAME, WTYPE) \ - typedef class AtomicWord<WTYPE> NAME; \ - namespace { \ - static_assert(sizeof(NAME) == sizeof(WTYPE), "sizeof(NAME) == sizeof(WTYPE)"); \ - static_assert(std::is_standard_layout<WTYPE>::value, "std::is_standard_layout<WTYPE>::value"); \ +#define _ATOMIC_WORD_DECLARE(NAME, WTYPE) \ + typedef class AtomicWord<WTYPE> NAME; \ + namespace { \ + MONGO_STATIC_ASSERT(sizeof(NAME) == sizeof(WTYPE)); \ + MONGO_STATIC_ASSERT(std::is_standard_layout<WTYPE>::value); \ } // namespace _ATOMIC_WORD_DECLARE(AtomicUInt32, unsigned); diff --git a/src/mongo/platform/decimal128.cpp b/src/mongo/platform/decimal128.cpp index 8d6dad6f7e4..d6a57fde649 100644 --- a/src/mongo/platform/decimal128.cpp +++ b/src/mongo/platform/decimal128.cpp @@ -44,6 +44,7 @@ #include <third_party/IntelRDFPMathLib20U1/LIBRARY/src/bid_functions.h> #undef _WCHAR_T +#include "mongo/base/static_assert.h" #include "mongo/config.h" #include "mongo/util/assert_util.h" #include "mongo/util/stringutils.h" @@ -841,8 +842,8 @@ const std::uint64_t t17hi32 = t17 >> 32; // t17hi32*t17hi32 + 2*t17hi32*t17lo32 + t17lo32*t17lo32 where the 2nd term // is shifted right by 32 and the 3rd term by 64 (which effectively drops the 3rd term) const std::uint64_t t34hi64 = t17hi32 * t17hi32 + (((t17hi32 * t17lo32) >> 31)); -static_assert(t34hi64 == 0x1ed09bead87c0, ""); -static_assert(t34lo64 == 0x378d8e63ffffffff, ""); +MONGO_STATIC_ASSERT(t34hi64 == 0x1ed09bead87c0); +MONGO_STATIC_ASSERT(t34lo64 == 0x378d8e63ffffffff); } // namespace // (t34hi64 << 64) + t34lo64 == 1e34 - 1 diff --git a/src/mongo/platform/endian.h b/src/mongo/platform/endian.h index faa6f686e29..f94586dc84a 100644 --- a/src/mongo/platform/endian.h +++ b/src/mongo/platform/endian.h @@ -32,6 +32,7 @@ #include <cstring> #include <type_traits> +#include "mongo/base/static_assert.h" #include "mongo/config.h" #include "mongo/platform/decimal128.h" @@ -340,7 +341,7 @@ struct ByteOrderConverter<float> { typedef float T; inline static T nativeToBig(T t) { - static_assert(sizeof(T) == sizeof(uint32_t), "sizeof(T) == sizeof(uint32_t)"); + MONGO_STATIC_ASSERT(sizeof(T) == sizeof(uint32_t)); uint32_t temp; std::memcpy(&temp, &t, sizeof(t)); @@ -379,7 +380,7 @@ struct ByteOrderConverter<double> { typedef double T; inline static T nativeToBig(T t) { - static_assert(sizeof(T) == sizeof(uint64_t), "sizeof(T) == sizeof(uint64_t)"); + MONGO_STATIC_ASSERT(sizeof(T) == sizeof(uint64_t)); uint64_t temp; std::memcpy(&temp, &t, sizeof(t)); @@ -452,32 +453,31 @@ struct IntegralTypeMap { template <> struct IntegralTypeMap<signed char> { - static_assert(CHAR_BIT == 8, "CHAR_BIT == 8"); + MONGO_STATIC_ASSERT(CHAR_BIT == 8); typedef int8_t type; }; template <> struct IntegralTypeMap<unsigned char> { - static_assert(CHAR_BIT == 8, "CHAR_BIT == 8"); + MONGO_STATIC_ASSERT(CHAR_BIT == 8); typedef uint8_t type; }; template <> struct IntegralTypeMap<char> { - static_assert(CHAR_BIT == 8, "CHAR_BIT == 8"); + MONGO_STATIC_ASSERT(CHAR_BIT == 8); typedef std::conditional<std::is_signed<char>::value, int8_t, uint8_t>::type type; }; template <> struct IntegralTypeMap<long long> { - static_assert(sizeof(long long) == sizeof(int64_t), "sizeof(long long) == sizeof(int64_t)"); + MONGO_STATIC_ASSERT(sizeof(long long) == sizeof(int64_t)); typedef int64_t type; }; template <> struct IntegralTypeMap<unsigned long long> { - static_assert(sizeof(unsigned long long) == sizeof(uint64_t), - "sizeof(unsigned long long) == sizeof(uint64_t)"); + MONGO_STATIC_ASSERT(sizeof(unsigned long long) == sizeof(uint64_t)); typedef uint64_t type; }; diff --git a/src/mongo/platform/process_id.cpp b/src/mongo/platform/process_id.cpp index 12bab6fbeab..d7b51bb064a 100644 --- a/src/mongo/platform/process_id.cpp +++ b/src/mongo/platform/process_id.cpp @@ -33,10 +33,11 @@ #include <limits> #include <sstream> +#include "mongo/base/static_assert.h" + namespace mongo { -static_assert(sizeof(NativeProcessId) == sizeof(uint32_t), - "sizeof(NativeProcessId) == sizeof(uint32_t)"); +MONGO_STATIC_ASSERT(sizeof(NativeProcessId) == sizeof(uint32_t)); namespace { #ifdef _WIN32 diff --git a/src/mongo/scripting/bson_template_evaluator.cpp b/src/mongo/scripting/bson_template_evaluator.cpp index 78df916a88e..e662b464270 100644 --- a/src/mongo/scripting/bson_template_evaluator.cpp +++ b/src/mongo/scripting/bson_template_evaluator.cpp @@ -31,6 +31,7 @@ #include <cstddef> #include <cstdlib> +#include "mongo/base/static_assert.h" #include "mongo/util/map_util.h" #include "mongo/util/mongoutils/str.h" @@ -269,7 +270,7 @@ BsonTemplateEvaluator::Status BsonTemplateEvaluator::evalRandString(BsonTemplate "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; static const size_t alphaNumLength = sizeof(alphanum) - 1; - static_assert(alphaNumLength == 64, "alphaNumLength == 64"); + MONGO_STATIC_ASSERT(alphaNumLength == 64); uint32_t currentRand = 0; std::string str; for (int i = 0; i < length; ++i, currentRand >>= 6) { diff --git a/src/mongo/scripting/mozjs/exception.cpp b/src/mongo/scripting/mozjs/exception.cpp index dd67fc41379..81f84dcb4d5 100644 --- a/src/mongo/scripting/mozjs/exception.cpp +++ b/src/mongo/scripting/mozjs/exception.cpp @@ -33,6 +33,7 @@ #include <jsfriendapi.h> #include <limits> +#include "mongo/base/static_assert.h" #include "mongo/scripting/mozjs/implscope.h" #include "mongo/scripting/mozjs/jsstringwrapper.h" #include "mongo/scripting/mozjs/objectwrapper.h" @@ -54,8 +55,9 @@ const JSErrorFormatString* uncatchableErrorCallback(void* data, const unsigned c return &kUncatchableErrorFormatString; } -static_assert(UINT_MAX - JSErr_Limit > ErrorCodes::MaxError, - "Not enough space in an unsigned int for Mongo ErrorCodes and JSErrorNumbers"); +MONGO_STATIC_ASSERT_MSG( + UINT_MAX - JSErr_Limit > ErrorCodes::MaxError, + "Not enough space in an unsigned int for Mongo ErrorCodes and JSErrorNumbers"); } // namespace diff --git a/src/mongo/util/decoration_registry.h b/src/mongo/util/decoration_registry.h index 5d04925c3db..408d24e1a51 100644 --- a/src/mongo/util/decoration_registry.h +++ b/src/mongo/util/decoration_registry.h @@ -32,6 +32,7 @@ #include <vector> #include "mongo/base/disallow_copying.h" +#include "mongo/base/static_assert.h" #include "mongo/stdx/functional.h" #include "mongo/util/decoration_container.h" @@ -59,8 +60,8 @@ public: */ template <typename T> DecorationContainer::DecorationDescriptorWithType<T> declareDecoration() { - static_assert(std::is_nothrow_destructible<T>::value, - "Decorations must be nothrow destructible"); + MONGO_STATIC_ASSERT_MSG(std::is_nothrow_destructible<T>::value, + "Decorations must be nothrow destructible"); return DecorationContainer::DecorationDescriptorWithType<T>(std::move(declareDecoration( sizeof(T), std::alignment_of<T>::value, &constructAt<T>, &destructAt<T>))); } diff --git a/src/mongo/util/duration.h b/src/mongo/util/duration.h index 353cb1fca9f..a040dd38d64 100644 --- a/src/mongo/util/duration.h +++ b/src/mongo/util/duration.h @@ -32,6 +32,7 @@ #include <limits> #include <ratio> +#include "mongo/base/static_assert.h" #include "mongo/platform/overflow_arithmetic.h" #include "mongo/stdx/chrono.h" #include "mongo/stdx/type_traits.h" @@ -147,8 +148,8 @@ inline long long durationCount(const stdx::chrono::duration<RepIn, PeriodIn>& d) template <typename Period> class Duration { public: - static_assert(Period::num > 0, "Duration::period's numerator must be positive"); - static_assert(Period::den > 0, "Duration::period's denominator must be positive"); + MONGO_STATIC_ASSERT_MSG(Period::num > 0, "Duration::period's numerator must be positive"); + MONGO_STATIC_ASSERT_MSG(Period::den > 0, "Duration::period's denominator must be positive"); using rep = int64_t; using period = Period; @@ -160,9 +161,10 @@ public: template <typename OtherDuration> struct IsHigherPrecisionThan { using OtherOverThis = std::ratio_divide<typename OtherDuration::period, period>; - static_assert(OtherOverThis::den == 1 || OtherOverThis::num == 1, - "Mongo duration types are only compatible with each other when one's period " - "is an even multiple of the other's."); + MONGO_STATIC_ASSERT_MSG( + OtherOverThis::den == 1 || OtherOverThis::num == 1, + "Mongo duration types are only compatible with each other when one's period " + "is an even multiple of the other's."); static constexpr bool value = OtherOverThis::den == 1 && OtherOverThis::num != 1; }; @@ -173,9 +175,10 @@ public: template <typename OtherDuration> struct IsLowerPrecisionThan { using OtherOverThis = std::ratio_divide<typename OtherDuration::period, period>; - static_assert(OtherOverThis::den == 1 || OtherOverThis::num == 1, - "Mongo duration types are only compatible with each other when one's period " - "is an even multiple of the other's."); + MONGO_STATIC_ASSERT_MSG( + OtherOverThis::den == 1 || OtherOverThis::num == 1, + "Mongo duration types are only compatible with each other when one's period " + "is an even multiple of the other's."); static constexpr bool value = OtherOverThis::num == 1 && OtherOverThis::den != 1; }; @@ -220,9 +223,10 @@ public: stdx::enable_if_t<std::is_convertible<Rep2, rep>::value && std::is_integral<Rep2>::value, int> = 0> constexpr explicit Duration(const Rep2& r) : _count(r) { - static_assert(std::is_signed<Rep2>::value || sizeof(Rep2) < sizeof(rep), - "Durations must be constructed from values of integral type that are " - "representable as 64-bit signed integers"); + MONGO_STATIC_ASSERT_MSG( + std::is_signed<Rep2>::value || sizeof(Rep2) < sizeof(rep), + "Durations must be constructed from values of integral type that are " + "representable as 64-bit signed integers"); } /** @@ -236,9 +240,10 @@ public: template <typename FromPeriod> /*implicit*/ Duration(const Duration<FromPeriod>& from) : Duration(duration_cast<Duration>(from)) { - static_assert(!isLowerPrecisionThan<Duration<FromPeriod>>(), - "Use duration_cast to convert from higher precision Duration types to lower " - "precision ones"); + MONGO_STATIC_ASSERT_MSG( + !isLowerPrecisionThan<Duration<FromPeriod>>(), + "Use duration_cast to convert from higher precision Duration types to lower " + "precision ones"); } stdx::chrono::system_clock::duration toSystemDuration() const { @@ -337,8 +342,9 @@ public: template <typename Rep2> Duration& operator*=(const Rep2& scale) { - static_assert(std::is_integral<Rep2>::value && std::is_signed<Rep2>::value, - "Durations may only be multiplied by values of signed integral type"); + MONGO_STATIC_ASSERT_MSG( + std::is_integral<Rep2>::value && std::is_signed<Rep2>::value, + "Durations may only be multiplied by values of signed integral type"); uassert(ErrorCodes::DurationOverflow, str::stream() << "Overflow while multiplying " << *this << " by " << scale, !mongoSignedMultiplyOverflow64(count(), scale, &_count)); @@ -347,8 +353,8 @@ public: template <typename Rep2> Duration& operator/=(const Rep2& scale) { - static_assert(std::is_integral<Rep2>::value && std::is_signed<Rep2>::value, - "Durations may only be divided by values of signed integral type"); + MONGO_STATIC_ASSERT_MSG(std::is_integral<Rep2>::value && std::is_signed<Rep2>::value, + "Durations may only be divided by values of signed integral type"); uassert(ErrorCodes::DurationOverflow, str::stream() << "Overflow while dividing " << *this << " by -1", (count() != min().count() || scale != -1)); diff --git a/src/mongo/util/heap_profiler.cpp b/src/mongo/util/heap_profiler.cpp index aa012a6388e..c2410ef2734 100644 --- a/src/mongo/util/heap_profiler.cpp +++ b/src/mongo/util/heap_profiler.cpp @@ -31,6 +31,7 @@ #include "mongo/platform/basic.h" #include "mongo/base/init.h" +#include "mongo/base/static_assert.h" #include "mongo/config.h" #include "mongo/db/commands/server_status.h" #include "mongo/db/server_parameters.h" @@ -310,8 +311,8 @@ private: Hash hash() { Hash hash; - static_assert(sizeof(frames) == sizeof(FrameInfo) * kMaxFramesPerStack, - "frames array is not dense"); + MONGO_STATIC_ASSERT_MSG(sizeof(frames) == sizeof(FrameInfo) * kMaxFramesPerStack, + "frames array is not dense"); MurmurHash3_x86_32(frames.data(), numFrames * sizeof(FrameInfo), 0, &hash); return hash; } diff --git a/src/mongo/util/net/asio_message_port.cpp b/src/mongo/util/net/asio_message_port.cpp index d883a474ab0..19413c53435 100644 --- a/src/mongo/util/net/asio_message_port.cpp +++ b/src/mongo/util/net/asio_message_port.cpp @@ -35,6 +35,7 @@ #include <set> #include "mongo/base/init.h" +#include "mongo/base/static_assert.h" #include "mongo/config.h" #include "mongo/stdx/memory.h" #include "mongo/util/fail_point_service.h" @@ -350,8 +351,8 @@ bool ASIOMessagingPort::recv(Message& m) { } if (_awaitingHandshake) { - static_assert(sizeof(kGET) - 1 <= kHeaderLen, - "HTTP GET string must be smaller than the message header."); + MONGO_STATIC_ASSERT_MSG(sizeof(kGET) - 1 <= kHeaderLen, + "HTTP GET string must be smaller than the message header."); if (memcmp(md.view2ptr(), kGET, strlen(kGET)) == 0) { std::string httpMsg = "It looks like you are trying to access MongoDB over HTTP on the native driver " diff --git a/src/mongo/util/net/message.h b/src/mongo/util/net/message.h index 69501802238..e1277917b44 100644 --- a/src/mongo/util/net/message.h +++ b/src/mongo/util/net/message.h @@ -35,6 +35,7 @@ #include "mongo/base/data_view.h" #include "mongo/base/disallow_copying.h" #include "mongo/base/encoded_value_storage.h" +#include "mongo/base/static_assert.h" #include "mongo/platform/atomic_word.h" #include "mongo/util/allocator.h" #include "mongo/util/mongoutils/str.h" @@ -278,7 +279,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) {} @@ -394,7 +395,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) {} diff --git a/src/mongo/util/represent_as.h b/src/mongo/util/represent_as.h index 2bdb12ce06e..f85805adbee 100644 --- a/src/mongo/util/represent_as.h +++ b/src/mongo/util/represent_as.h @@ -34,6 +34,7 @@ #include <boost/optional.hpp> +#include "mongo/base/static_assert.h" #include "mongo/stdx/type_traits.h" namespace mongo { @@ -48,7 +49,7 @@ namespace detail { // Floating point numbers -> double template <typename T> typename stdx::enable_if_t<std::is_floating_point<T>::value, double> upconvert(T t) { - static_assert(sizeof(double) >= sizeof(T), "sizeof(double) >= sizeof(T)"); + MONGO_STATIC_ASSERT(sizeof(double) >= sizeof(T)); return static_cast<double>(t); } @@ -56,7 +57,7 @@ typename stdx::enable_if_t<std::is_floating_point<T>::value, double> upconvert(T template <typename T> typename stdx::enable_if_t<std::is_integral<T>::value && std::is_signed<T>::value, int64_t> upconvert(T t) { - static_assert(sizeof(int64_t) >= sizeof(T), "sizeof(int64_t) >= sizeof(T)"); + MONGO_STATIC_ASSERT(sizeof(int64_t) >= sizeof(T)); return static_cast<int64_t>(t); } @@ -64,7 +65,7 @@ upconvert(T t) { template <typename T> typename stdx::enable_if_t<std::is_integral<T>::value && !std::is_signed<T>::value, uint64_t> upconvert(T t) { - static_assert(sizeof(uint64_t) >= sizeof(T), "sizeof(uint64_t) >= sizeof(T)"); + MONGO_STATIC_ASSERT(sizeof(uint64_t) >= sizeof(T)); return static_cast<uint64_t>(t); } |