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 /src/mongo/base | |
parent | ae280145c3c3dc770884a68885e80a282e8d50fd (diff) | |
download | mongo-2bd286acef2fdb035f1d45253f6e6e4c24a2dc04.tar.gz |
SERVER-22973 use mongo macros for static assert
Diffstat (limited to 'src/mongo/base')
-rw-r--r-- | src/mongo/base/data_type.h | 17 | ||||
-rw-r--r-- | src/mongo/base/encoded_value_storage_test.cpp | 3 | ||||
-rw-r--r-- | src/mongo/base/secure_allocator.h | 5 | ||||
-rw-r--r-- | src/mongo/base/static_assert.h | 32 | ||||
-rw-r--r-- | src/mongo/base/status_with.h | 4 |
5 files changed, 49 insertions, 12 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: /** |