diff options
author | avi <avi@chromium.org> | 2015-11-24 06:26:24 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-24 14:27:16 +0000 |
commit | 4ec0dffe9e013e64058ff506a76bc822957227aa (patch) | |
tree | 505796dd4533ddb36753b6391bb20e59fd1dbd9b | |
parent | bfd6ebdc7511f63ebae483cc82ce5ed989f470ca (diff) | |
download | chromium_src-4ec0dffe9e013e64058ff506a76bc822957227aa.zip chromium_src-4ec0dffe9e013e64058ff506a76bc822957227aa.tar.gz chromium_src-4ec0dffe9e013e64058ff506a76bc822957227aa.tar.bz2 |
Switch to static_assert in base/.
BUG=442514
Review URL: https://codereview.chromium.org/1467003002
Cr-Commit-Position: refs/heads/master@{#361337}
33 files changed, 145 insertions, 145 deletions
diff --git a/base/android/jni_android.cc b/base/android/jni_android.cc index d836744..26a266d 100644 --- a/base/android/jni_android.cc +++ b/base/android/jni_android.cc @@ -125,8 +125,8 @@ jclass LazyGetClass( JNIEnv* env, const char* class_name, base::subtle::AtomicWord* atomic_class_id) { - COMPILE_ASSERT(sizeof(subtle::AtomicWord) >= sizeof(jclass), - AtomicWord_SmallerThan_jMethodID); + static_assert(sizeof(subtle::AtomicWord) >= sizeof(jclass), + "AtomicWord can't be smaller than jclass"); subtle::AtomicWord value = base::subtle::Acquire_Load(atomic_class_id); if (value) return reinterpret_cast<jclass>(value); @@ -170,8 +170,8 @@ jmethodID MethodID::LazyGet(JNIEnv* env, const char* method_name, const char* jni_signature, base::subtle::AtomicWord* atomic_method_id) { - COMPILE_ASSERT(sizeof(subtle::AtomicWord) >= sizeof(jmethodID), - AtomicWord_SmallerThan_jMethodID); + static_assert(sizeof(subtle::AtomicWord) >= sizeof(jmethodID), + "AtomicWord can't be smaller than jMethodID"); subtle::AtomicWord value = base::subtle::Acquire_Load(atomic_method_id); if (value) return reinterpret_cast<jmethodID>(value); diff --git a/base/atomicops_internals_x86_msvc.h b/base/atomicops_internals_x86_msvc.h index 71ddca2..6ff0f44 100644 --- a/base/atomicops_internals_x86_msvc.h +++ b/base/atomicops_internals_x86_msvc.h @@ -109,7 +109,7 @@ inline Atomic32 Release_Load(volatile const Atomic32* ptr) { // 64-bit low-level operations on 64-bit platform. -COMPILE_ASSERT(sizeof(Atomic64) == sizeof(PVOID), atomic_word_is_atomic); +static_assert(sizeof(Atomic64) == sizeof(PVOID), "atomic word is atomic"); inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, Atomic64 old_value, diff --git a/base/bind.h b/base/bind.h index 51be10d..94da5ac 100644 --- a/base/bind.h +++ b/base/bind.h @@ -89,7 +89,7 @@ Bind(Functor functor, const Args&... args) { // invoked function will receive a reference to the stored copy of the // argument and not the original. static_assert(!internal::HasNonConstReferenceParam<BoundRunType>::value, - "do_not_bind_functions_with_nonconst_ref"); + "do not bind functions with nonconst ref"); const bool is_method = internal::HasIsMethodTag<RunnableType>::value; @@ -98,10 +98,10 @@ Bind(Functor functor, const Args&... args) { // methods. We also disallow binding of an array as the method's target // object. static_assert(!internal::BindsArrayToFirstArg<is_method, Args...>::value, - "first_bound_argument_to_method_cannot_be_array"); + "first bound argument to method cannot be array"); static_assert( !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value, - "a_parameter_is_refcounted_type_and_needs_scoped_refptr"); + "a parameter is a refcounted type and needs scoped_refptr"); typedef internal::BindState< RunnableType, RunType, diff --git a/base/bind_internal.h b/base/bind_internal.h index 1cb1684..c6832e6 100644 --- a/base/bind_internal.h +++ b/base/bind_internal.h @@ -313,8 +313,8 @@ struct InvokeHelper<true, ReturnType, Runnable, ArgsType> { // WeakCalls are only supported for functions with a void return type. // Otherwise, the function result would be undefined if the the WeakPtr<> // is invalidated. - COMPILE_ASSERT(is_void<ReturnType>::value, - weak_ptrs_can_only_bind_to_methods_without_return_values); + static_assert(is_void<ReturnType>::value, + "weak_ptrs can only bind to methods without return values"); }; #endif diff --git a/base/containers/small_map.h b/base/containers/small_map.h index df3d22a..8ae4219 100644 --- a/base/containers/small_map.h +++ b/base/containers/small_map.h @@ -187,7 +187,7 @@ class SmallMap { // particular, gcc 2.95.3 does it but later versions allow 0-length // arrays. Therefore, we explicitly reject non-positive kArraySize // here. - COMPILE_ASSERT(kArraySize > 0, default_initial_size_should_be_positive); + static_assert(kArraySize > 0, "default initial size should be positive"); public: typedef typename NormalMap::key_type key_type; diff --git a/base/containers/stack_container.h b/base/containers/stack_container.h index 54090d3..2c7dd65 100644 --- a/base/containers/stack_container.h +++ b/base/containers/stack_container.h @@ -57,7 +57,7 @@ class StackAllocator : public std::allocator<T> { // buffer of the right size instead. base::AlignedMemory<sizeof(T[stack_capacity]), ALIGNOF(T)> stack_buffer_; #if defined(__GNUC__) && !defined(ARCH_CPU_X86_FAMILY) - COMPILE_ASSERT(ALIGNOF(T) <= 16, crbug_115612); + static_assert(ALIGNOF(T) <= 16, "http://crbug.com/115612"); #endif // Set when the stack buffer is used for an allocation. We do not track diff --git a/base/files/file_posix.cc b/base/files/file_posix.cc index a5aee01..9760f04 100644 --- a/base/files/file_posix.cc +++ b/base/files/file_posix.cc @@ -22,9 +22,9 @@ namespace base { // Make sure our Whence mappings match the system headers. -COMPILE_ASSERT(File::FROM_BEGIN == SEEK_SET && - File::FROM_CURRENT == SEEK_CUR && - File::FROM_END == SEEK_END, whence_matches_system); +static_assert(File::FROM_BEGIN == SEEK_SET && File::FROM_CURRENT == SEEK_CUR && + File::FROM_END == SEEK_END, + "whence mapping must match the system headers"); namespace { @@ -184,11 +184,11 @@ int64 File::Seek(Whence whence, int64 offset) { SCOPED_FILE_TRACE_WITH_SIZE("Seek", offset); #if defined(OS_ANDROID) - COMPILE_ASSERT(sizeof(int64) == sizeof(off64_t), off64_t_64_bit); + static_assert(sizeof(int64) == sizeof(off64_t), "off64_t must be 64 bits"); return lseek64(file_.get(), static_cast<off64_t>(offset), static_cast<int>(whence)); #else - COMPILE_ASSERT(sizeof(int64) == sizeof(off_t), off_t_64_bit); + static_assert(sizeof(int64) == sizeof(off_t), "off_t must be 64 bits"); return lseek(file_.get(), static_cast<off_t>(offset), static_cast<int>(whence)); #endif @@ -471,7 +471,7 @@ void File::DoInitialize(const FilePath& path, uint32 flags) { else if (flags & FLAG_APPEND) open_flags |= O_APPEND | O_WRONLY; - COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero); + static_assert(O_RDONLY == 0, "O_RDONLY must equal zero"); int mode = S_IRUSR | S_IWUSR; #if defined(OS_CHROMEOS) diff --git a/base/files/file_win.cc b/base/files/file_win.cc index 2d75ca2..c2cc3ab 100644 --- a/base/files/file_win.cc +++ b/base/files/file_win.cc @@ -13,9 +13,10 @@ namespace base { // Make sure our Whence mappings match the system headers. -COMPILE_ASSERT(File::FROM_BEGIN == FILE_BEGIN && - File::FROM_CURRENT == FILE_CURRENT && - File::FROM_END == FILE_END, whence_matches_system); +static_assert(File::FROM_BEGIN == FILE_BEGIN && + File::FROM_CURRENT == FILE_CURRENT && + File::FROM_END == FILE_END, + "whence mapping must match the system headers"); bool File::IsValid() const { return file_.IsValid(); diff --git a/base/json/json_reader.cc b/base/json/json_reader.cc index 2050b0f..015df43 100644 --- a/base/json/json_reader.cc +++ b/base/json/json_reader.cc @@ -11,8 +11,8 @@ namespace base { // Values 1000 and above are used by JSONFileValueSerializer::JsonFileError. -COMPILE_ASSERT(JSONReader::JSON_PARSE_ERROR_COUNT < 1000, - json_reader_error_out_of_bounds); +static_assert(JSONReader::JSON_PARSE_ERROR_COUNT < 1000, + "JSONReader error out of bounds"); const char JSONReader::kInvalidEscape[] = "Invalid escape sequence."; diff --git a/base/json/string_escape.cc b/base/json/string_escape.cc index f5d6a76..3221a3c 100644 --- a/base/json/string_escape.cc +++ b/base/json/string_escape.cc @@ -23,7 +23,7 @@ const char kU16EscapeFormat[] = "\\u%04X"; const uint32 kReplacementCodePoint = 0xFFFD; // Used below in EscapeSpecialCodePoint(). -COMPILE_ASSERT('<' == 0x3C, less_than_sign_is_0x3c); +static_assert('<' == 0x3C, "less than sign must be 0x3c"); // Try to escape the |code_point| if it is a known special character. If // successful, returns true and appends the escape sequence to |dest|. This diff --git a/base/logging.h b/base/logging.h index 8c7f20a..a78b786 100644 --- a/base/logging.h +++ b/base/logging.h @@ -952,9 +952,9 @@ inline std::ostream& operator<<(std::ostream& out, const std::wstring& wstr) { #define NOTIMPLEMENTED() EAT_STREAM_PARAMETERS #elif NOTIMPLEMENTED_POLICY == 1 // TODO, figure out how to generate a warning -#define NOTIMPLEMENTED() COMPILE_ASSERT(false, NOT_IMPLEMENTED) +#define NOTIMPLEMENTED() static_assert(false, "NOT_IMPLEMENTED") #elif NOTIMPLEMENTED_POLICY == 2 -#define NOTIMPLEMENTED() COMPILE_ASSERT(false, NOT_IMPLEMENTED) +#define NOTIMPLEMENTED() static_assert(false, "NOT_IMPLEMENTED") #elif NOTIMPLEMENTED_POLICY == 3 #define NOTIMPLEMENTED() NOTREACHED() #elif NOTIMPLEMENTED_POLICY == 4 diff --git a/base/mac/foundation_util_unittest.mm b/base/mac/foundation_util_unittest.mm index c688442..69d5b1f 100644 --- a/base/mac/foundation_util_unittest.mm +++ b/base/mac/foundation_util_unittest.mm @@ -281,8 +281,8 @@ TEST(FoundationUtilTest, GetValueFromDictionary) { CFStringRef keys[] = { CFSTR("one"), CFSTR("two"), CFSTR("three") }; CFNumberRef values[] = { cf_one, cf_two, cf_three }; - COMPILE_ASSERT(arraysize(keys) == arraysize(values), - keys_and_values_arraysizes_are_different); + static_assert(arraysize(keys) == arraysize(values), + "keys and values arrays must have the same size"); ScopedCFTypeRef<CFDictionaryRef> test_dict( CFDictionaryCreate(kCFAllocatorDefault, diff --git a/base/macros.h b/base/macros.h index c5f503f..65c7749 100644 --- a/base/macros.h +++ b/base/macros.h @@ -129,7 +129,8 @@ template <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N]; template <class Dest, class Source> inline Dest bit_cast(const Source& source) { - COMPILE_ASSERT(sizeof(Dest) == sizeof(Source), VerifySizesAreEqual); + static_assert(sizeof(Dest) == sizeof(Source), + "bit_cast requires source and destination to be the same size"); Dest dest; memcpy(&dest, &source, sizeof(dest)); diff --git a/base/memory/scoped_ptr.h b/base/memory/scoped_ptr.h index b3d5a35..51750d3 100644 --- a/base/memory/scoped_ptr.h +++ b/base/memory/scoped_ptr.h @@ -239,8 +239,8 @@ template <class T, class D = std::default_delete<T>> class scoped_ptr { MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(scoped_ptr) - COMPILE_ASSERT(base::internal::IsNotRefCounted<T>::value, - T_is_refcounted_type_and_needs_scoped_refptr); + static_assert(base::internal::IsNotRefCounted<T>::value, + "T is a refcounted type and needs a scoped_refptr"); public: // The element and deleter types. diff --git a/base/memory/scoped_ptr_unittest.cc b/base/memory/scoped_ptr_unittest.cc index 6330bb9..60a050e 100644 --- a/base/memory/scoped_ptr_unittest.cc +++ b/base/memory/scoped_ptr_unittest.cc @@ -102,8 +102,8 @@ TEST(ScopedPtrTest, ScopedPtr) { int constructed = 0; // Ensure size of scoped_ptr<> doesn't increase unexpectedly. - COMPILE_ASSERT(sizeof(int*) >= sizeof(scoped_ptr<int>), - scoped_ptr_larger_than_raw_ptr); + static_assert(sizeof(int*) >= sizeof(scoped_ptr<int>), + "scoped_ptr shouldn't be larger than the raw pointer"); { scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed)); diff --git a/base/memory/singleton_unittest.cc b/base/memory/singleton_unittest.cc index e8788ba..28daf10 100644 --- a/base/memory/singleton_unittest.cc +++ b/base/memory/singleton_unittest.cc @@ -9,7 +9,8 @@ namespace base { namespace { -COMPILE_ASSERT(DefaultSingletonTraits<int>::kRegisterAtExit == true, a); +static_assert(DefaultSingletonTraits<int>::kRegisterAtExit == true, + "object must be deleted on process exit"); typedef void (*CallbackFunc)(); diff --git a/base/memory/weak_ptr.h b/base/memory/weak_ptr.h index c335ae9..c62f29c 100644 --- a/base/memory/weak_ptr.h +++ b/base/memory/weak_ptr.h @@ -161,8 +161,8 @@ class SupportsWeakPtrBase { static WeakPtr<Derived> StaticAsWeakPtr(Derived* t) { typedef is_convertible<Derived, internal::SupportsWeakPtrBase&> convertible; - COMPILE_ASSERT(convertible::value, - AsWeakPtr_argument_inherits_from_SupportsWeakPtr); + static_assert(convertible::value, + "AsWeakPtr argument must inherit from SupportsWeakPtr"); return AsWeakPtrImpl<Derived>(t, *t); } diff --git a/base/message_loop/message_loop.h b/base/message_loop/message_loop.h index 77edfdb..6e4be9d 100644 --- a/base/message_loop/message_loop.h +++ b/base/message_loop/message_loop.h @@ -601,8 +601,8 @@ class BASE_EXPORT MessageLoopForUI : public MessageLoop { // Do not add any member variables to MessageLoopForUI! This is important b/c // MessageLoopForUI is often allocated via MessageLoop(TYPE_UI). Any extra // data that you need should be stored on the MessageLoop's pump_ instance. -COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForUI), - MessageLoopForUI_should_not_have_extra_member_variables); +static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForUI), + "MessageLoopForUI should not have extra member variables"); #endif // !defined(OS_NACL) @@ -682,8 +682,8 @@ class BASE_EXPORT MessageLoopForIO : public MessageLoop { // Do not add any member variables to MessageLoopForIO! This is important b/c // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra // data that you need should be stored on the MessageLoop's pump_ instance. -COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), - MessageLoopForIO_should_not_have_extra_member_variables); +static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), + "MessageLoopForIO should not have extra member variables"); } // namespace base diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc index 2ad7517..e9e3be2 100644 --- a/base/metrics/field_trial.cc +++ b/base/metrics/field_trial.cc @@ -325,12 +325,11 @@ FieldTrial* FieldTrialList::FactoryGetFieldTrialWithRandomizationSeed( // group number, so that it does not conflict with the |AppendGroup()| // result for the chosen group. const int kNonConflictingGroupNumber = -2; - COMPILE_ASSERT( + static_assert( kNonConflictingGroupNumber != FieldTrial::kDefaultGroupNumber, - conflicting_default_group_number); - COMPILE_ASSERT( - kNonConflictingGroupNumber != FieldTrial::kNotFinalized, - conflicting_default_group_number); + "The 'non-conflicting' group number conflicts"); + static_assert(kNonConflictingGroupNumber != FieldTrial::kNotFinalized, + "The 'non-conflicting' group number conflicts"); *default_group_number = kNonConflictingGroupNumber; } } diff --git a/base/observer_list_threadsafe.h b/base/observer_list_threadsafe.h index b9b4a62..e420494 100644 --- a/base/observer_list_threadsafe.h +++ b/base/observer_list_threadsafe.h @@ -67,9 +67,8 @@ template <class T, class Method, class Params> class UnboundMethod { public: UnboundMethod(Method m, const Params& p) : m_(m), p_(p) { - COMPILE_ASSERT( - (internal::ParamsUseScopedRefptrCorrectly<Params>::value), - badunboundmethodparams); + static_assert((internal::ParamsUseScopedRefptrCorrectly<Params>::value), + "bad unbound method params"); } void Run(T* obj) const { DispatchToMethod(obj, m_, p_); diff --git a/base/rand_util.cc b/base/rand_util.cc index e12088e..1a3b79e 100644 --- a/base/rand_util.cc +++ b/base/rand_util.cc @@ -38,7 +38,8 @@ double BitsToOpenEndedUnitInterval(uint64_t bits) { // produce output in the range [0, 1). For IEEE 754 doubles, the mantissa // is expected to accommodate 53 bits. - COMPILE_ASSERT(std::numeric_limits<double>::radix == 2, otherwise_use_scalbn); + static_assert(std::numeric_limits<double>::radix == 2, + "otherwise use scalbn"); static const int kBits = std::numeric_limits<double>::digits; uint64_t random_bits = bits & ((UINT64_C(1) << kBits) - 1); double result = ldexp(static_cast<double>(random_bits), -1 * kBits); diff --git a/base/strings/safe_sprintf.cc b/base/strings/safe_sprintf.cc index 6aa1cbe..9719abd 100644 --- a/base/strings/safe_sprintf.cc +++ b/base/strings/safe_sprintf.cc @@ -72,7 +72,7 @@ const char kDownCaseHexDigits[] = "0123456789abcdef"; #if defined(NDEBUG) // We would like to define kSSizeMax as std::numeric_limits<ssize_t>::max(), // but C++ doesn't allow us to do that for constants. Instead, we have to -// use careful casting and shifting. We later use a COMPILE_ASSERT to +// use careful casting and shifting. We later use a static_assert to // verify that this worked correctly. namespace { const size_t kSSizeMax = kSSizeMaxConst; @@ -110,18 +110,13 @@ class Buffer { : buffer_(buffer), size_(size - 1), // Account for trailing NUL byte count_(0) { -// The following assertion does not build on Mac and Android. This is because -// static_assert only works with compile-time constants, but mac uses -// libstdc++4.2 and android uses stlport, which both don't mark -// numeric_limits::max() as constexp. Likewise, MSVS2013's standard library -// also doesn't mark max() as constexpr yet. cl.exe supports static_cast but -// doesn't really implement constexpr yet so it doesn't complain, but clang -// does. -#if __cplusplus >= 201103 && !defined(OS_ANDROID) && !defined(OS_MACOSX) && \ - !defined(OS_IOS) && !(defined(__clang__) && defined(OS_WIN)) - COMPILE_ASSERT(kSSizeMaxConst == \ - static_cast<size_t>(std::numeric_limits<ssize_t>::max()), - kSSizeMax_is_the_max_value_of_an_ssize_t); +// MSVS2013's standard library doesn't mark max() as constexpr yet. cl.exe +// supports static_cast but doesn't really implement constexpr yet so it doesn't +// complain, but clang does. +#if __cplusplus >= 201103 && !(defined(__clang__) && defined(OS_WIN)) + static_assert(kSSizeMaxConst == + static_cast<size_t>(std::numeric_limits<ssize_t>::max()), + "kSSizeMaxConst should be the max value of an ssize_t"); #endif DEBUG_CHECK(size > 0); DEBUG_CHECK(size <= kSSizeMax); diff --git a/base/strings/string16.h b/base/strings/string16.h index 1a01a96..ba4ffe7 100644 --- a/base/strings/string16.h +++ b/base/strings/string16.h @@ -64,7 +64,8 @@ struct string16_char_traits { // int_type needs to be able to hold each possible value of char_type, and in // addition, the distinct value of eof(). - COMPILE_ASSERT(sizeof(int_type) > sizeof(char_type), unexpected_type_width); + static_assert(sizeof(int_type) > sizeof(char_type), + "int must be larger than 16 bits wide"); typedef std::streamoff off_type; typedef mbstate_t state_type; diff --git a/base/sync_socket_unittest.cc b/base/sync_socket_unittest.cc index 7c8c97c..0a2f3a7e 100644 --- a/base/sync_socket_unittest.cc +++ b/base/sync_socket_unittest.cc @@ -49,7 +49,7 @@ class HangingReceiveThread : public base::DelegateSimpleThread::Delegate { void SendReceivePeek(base::SyncSocket* socket_a, base::SyncSocket* socket_b) { int received = 0; const int kSending = 123; - COMPILE_ASSERT(sizeof(kSending) == sizeof(received), Invalid_Data_Size); + static_assert(sizeof(kSending) == sizeof(received), "invalid data size"); ASSERT_EQ(0u, socket_a->Peek()); ASSERT_EQ(0u, socket_b->Peek()); diff --git a/base/sync_socket_win.cc b/base/sync_socket_win.cc index e16b925..4b5040c 100644 --- a/base/sync_socket_win.cc +++ b/base/sync_socket_win.cc @@ -121,7 +121,7 @@ size_t CancelableFileOperation(Function operation, DWORD timeout_in_ms) { ThreadRestrictions::AssertIOAllowed(); // The buffer must be byte size or the length check won't make much sense. - COMPILE_ASSERT(sizeof(buffer[0]) == sizeof(char), incorrect_buffer_type); + static_assert(sizeof(buffer[0]) == sizeof(char), "incorrect buffer type"); DCHECK_GT(length, 0u); DCHECK_LE(length, kMaxMessageLength); DCHECK_NE(file, SyncSocket::kInvalidHandle); diff --git a/base/template_util_unittest.cc b/base/template_util_unittest.cc index 3ec3887..32883f2 100644 --- a/base/template_util_unittest.cc +++ b/base/template_util_unittest.cc @@ -18,23 +18,24 @@ class Parent {}; class Child : public Parent {}; // is_pointer<Type> -COMPILE_ASSERT(!is_pointer<int>::value, IsPointer); -COMPILE_ASSERT(!is_pointer<int&>::value, IsPointer); -COMPILE_ASSERT(is_pointer<int*>::value, IsPointer); -COMPILE_ASSERT(is_pointer<const int*>::value, IsPointer); +static_assert(!is_pointer<int>::value, "IsPointer"); +static_assert(!is_pointer<int&>::value, "IsPointer"); +static_assert(is_pointer<int*>::value, "IsPointer"); +static_assert(is_pointer<const int*>::value, "IsPointer"); // is_array<Type> -COMPILE_ASSERT(!is_array<int>::value, IsArray); -COMPILE_ASSERT(!is_array<int*>::value, IsArray); -COMPILE_ASSERT(!is_array<int(*)[3]>::value, IsArray); -COMPILE_ASSERT(is_array<int[]>::value, IsArray); -COMPILE_ASSERT(is_array<const int[]>::value, IsArray); -COMPILE_ASSERT(is_array<int[3]>::value, IsArray); +static_assert(!is_array<int>::value, "IsArray"); +static_assert(!is_array<int*>::value, "IsArray"); +static_assert(!is_array<int (*)[3]>::value, "IsArray"); +static_assert(is_array<int[]>::value, "IsArray"); +static_assert(is_array<const int[]>::value, "IsArray"); +static_assert(is_array<int[3]>::value, "IsArray"); // is_non_const_reference<Type> -COMPILE_ASSERT(!is_non_const_reference<int>::value, IsNonConstReference); -COMPILE_ASSERT(!is_non_const_reference<const int&>::value, IsNonConstReference); -COMPILE_ASSERT(is_non_const_reference<int&>::value, IsNonConstReference); +static_assert(!is_non_const_reference<int>::value, "IsNonConstReference"); +static_assert(!is_non_const_reference<const int&>::value, + "IsNonConstReference"); +static_assert(is_non_const_reference<int&>::value, "IsNonConstReference"); // is_convertible<From, To> @@ -44,66 +45,64 @@ COMPILE_ASSERT(is_non_const_reference<int&>::value, IsNonConstReference); // (is_convertible < Child), (Parent > ::value) // // Silly C++. -COMPILE_ASSERT( (is_convertible<Child, Parent>::value), IsConvertible); -COMPILE_ASSERT(!(is_convertible<Parent, Child>::value), IsConvertible); -COMPILE_ASSERT(!(is_convertible<Parent, AStruct>::value), IsConvertible); -COMPILE_ASSERT( (is_convertible<int, double>::value), IsConvertible); -COMPILE_ASSERT( (is_convertible<int*, void*>::value), IsConvertible); -COMPILE_ASSERT(!(is_convertible<void*, int*>::value), IsConvertible); +static_assert((is_convertible<Child, Parent>::value), "IsConvertible"); +static_assert(!(is_convertible<Parent, Child>::value), "IsConvertible"); +static_assert(!(is_convertible<Parent, AStruct>::value), "IsConvertible"); +static_assert((is_convertible<int, double>::value), "IsConvertible"); +static_assert((is_convertible<int*, void*>::value), "IsConvertible"); +static_assert(!(is_convertible<void*, int*>::value), "IsConvertible"); // Array types are an easy corner case. Make sure to test that // it does indeed compile. -COMPILE_ASSERT(!(is_convertible<int[10], double>::value), IsConvertible); -COMPILE_ASSERT(!(is_convertible<double, int[10]>::value), IsConvertible); -COMPILE_ASSERT( (is_convertible<int[10], int*>::value), IsConvertible); +static_assert(!(is_convertible<int[10], double>::value), "IsConvertible"); +static_assert(!(is_convertible<double, int[10]>::value), "IsConvertible"); +static_assert((is_convertible<int[10], int*>::value), "IsConvertible"); // is_same<Type1, Type2> -COMPILE_ASSERT(!(is_same<Child, Parent>::value), IsSame); -COMPILE_ASSERT(!(is_same<Parent, Child>::value), IsSame); -COMPILE_ASSERT( (is_same<Parent, Parent>::value), IsSame); -COMPILE_ASSERT( (is_same<int*, int*>::value), IsSame); -COMPILE_ASSERT( (is_same<int, int>::value), IsSame); -COMPILE_ASSERT( (is_same<void, void>::value), IsSame); -COMPILE_ASSERT(!(is_same<int, double>::value), IsSame); - +static_assert(!(is_same<Child, Parent>::value), "IsSame"); +static_assert(!(is_same<Parent, Child>::value), "IsSame"); +static_assert((is_same<Parent, Parent>::value), "IsSame"); +static_assert((is_same<int*, int*>::value), "IsSame"); +static_assert((is_same<int, int>::value), "IsSame"); +static_assert((is_same<void, void>::value), "IsSame"); +static_assert(!(is_same<int, double>::value), "IsSame"); // is_class<Type> -COMPILE_ASSERT(is_class<AStruct>::value, IsClass); -COMPILE_ASSERT(is_class<AClass>::value, IsClass); -COMPILE_ASSERT(!is_class<AnEnum>::value, IsClass); -COMPILE_ASSERT(!is_class<int>::value, IsClass); -COMPILE_ASSERT(!is_class<char*>::value, IsClass); -COMPILE_ASSERT(!is_class<int&>::value, IsClass); -COMPILE_ASSERT(!is_class<char[3]>::value, IsClass); - - -COMPILE_ASSERT(!is_member_function_pointer<int>::value, - IsMemberFunctionPointer); -COMPILE_ASSERT(!is_member_function_pointer<int*>::value, - IsMemberFunctionPointer); -COMPILE_ASSERT(!is_member_function_pointer<void*>::value, - IsMemberFunctionPointer); -COMPILE_ASSERT(!is_member_function_pointer<AStruct>::value, - IsMemberFunctionPointer); -COMPILE_ASSERT(!is_member_function_pointer<AStruct*>::value, - IsMemberFunctionPointer); -COMPILE_ASSERT(!is_member_function_pointer<void(*)()>::value, - IsMemberFunctionPointer); -COMPILE_ASSERT(!is_member_function_pointer<int(*)(int)>::value, - IsMemberFunctionPointer); -COMPILE_ASSERT(!is_member_function_pointer<int(*)(int, int)>::value, - IsMemberFunctionPointer); - -COMPILE_ASSERT(is_member_function_pointer<void (AStruct::*)()>::value, - IsMemberFunctionPointer); -COMPILE_ASSERT(is_member_function_pointer<void (AStruct::*)(int)>::value, - IsMemberFunctionPointer); -COMPILE_ASSERT(is_member_function_pointer<int (AStruct::*)(int)>::value, - IsMemberFunctionPointer); -COMPILE_ASSERT(is_member_function_pointer<int (AStruct::*)(int) const>::value, - IsMemberFunctionPointer); -COMPILE_ASSERT(is_member_function_pointer<int (AStruct::*)(int, int)>::value, - IsMemberFunctionPointer); +static_assert(is_class<AStruct>::value, "IsClass"); +static_assert(is_class<AClass>::value, "IsClass"); +static_assert(!is_class<AnEnum>::value, "IsClass"); +static_assert(!is_class<int>::value, "IsClass"); +static_assert(!is_class<char*>::value, "IsClass"); +static_assert(!is_class<int&>::value, "IsClass"); +static_assert(!is_class<char[3]>::value, "IsClass"); + +static_assert(!is_member_function_pointer<int>::value, + "IsMemberFunctionPointer"); +static_assert(!is_member_function_pointer<int*>::value, + "IsMemberFunctionPointer"); +static_assert(!is_member_function_pointer<void*>::value, + "IsMemberFunctionPointer"); +static_assert(!is_member_function_pointer<AStruct>::value, + "IsMemberFunctionPointer"); +static_assert(!is_member_function_pointer<AStruct*>::value, + "IsMemberFunctionPointer"); +static_assert(!is_member_function_pointer<void (*)()>::value, + "IsMemberFunctionPointer"); +static_assert(!is_member_function_pointer<int (*)(int)>::value, + "IsMemberFunctionPointer"); +static_assert(!is_member_function_pointer<int (*)(int, int)>::value, + "IsMemberFunctionPointer"); + +static_assert(is_member_function_pointer<void (AStruct::*)()>::value, + "IsMemberFunctionPointer"); +static_assert(is_member_function_pointer<void (AStruct::*)(int)>::value, + "IsMemberFunctionPointer"); +static_assert(is_member_function_pointer<int (AStruct::*)(int)>::value, + "IsMemberFunctionPointer"); +static_assert(is_member_function_pointer<int (AStruct::*)(int) const>::value, + "IsMemberFunctionPointer"); +static_assert(is_member_function_pointer<int (AStruct::*)(int, int)>::value, + "IsMemberFunctionPointer"); } // namespace } // namespace base diff --git a/base/time/time_mac.cc b/base/time/time_mac.cc index 578e039..139e0c9 100644 --- a/base/time/time_mac.cc +++ b/base/time/time_mac.cc @@ -135,8 +135,8 @@ Time Time::Now() { // static Time Time::FromCFAbsoluteTime(CFAbsoluteTime t) { - COMPILE_ASSERT(std::numeric_limits<CFAbsoluteTime>::has_infinity, - numeric_limits_infinity_is_undefined_when_not_has_infinity); + static_assert(std::numeric_limits<CFAbsoluteTime>::has_infinity, + "CFAbsoluteTime must have an infinity value"); if (t == 0) return Time(); // Consider 0 as a null Time. if (t == std::numeric_limits<CFAbsoluteTime>::infinity()) @@ -147,8 +147,8 @@ Time Time::FromCFAbsoluteTime(CFAbsoluteTime t) { } CFAbsoluteTime Time::ToCFAbsoluteTime() const { - COMPILE_ASSERT(std::numeric_limits<CFAbsoluteTime>::has_infinity, - numeric_limits_infinity_is_undefined_when_not_has_infinity); + static_assert(std::numeric_limits<CFAbsoluteTime>::has_infinity, + "CFAbsoluteTime must have an infinity value"); if (is_null()) return 0; // Consider 0 as a null Time. if (is_max()) diff --git a/base/time/time_win_unittest.cc b/base/time/time_win_unittest.cc index 38798d5..baaa322 100644 --- a/base/time/time_win_unittest.cc +++ b/base/time/time_win_unittest.cc @@ -187,8 +187,8 @@ TEST(TimeTicks, TimerPerformance) { }; // Cheating a bit here: assumes sizeof(TimeTicks) == sizeof(Time) // in order to create a single test case list. - COMPILE_ASSERT(sizeof(TimeTicks) == sizeof(Time), - test_only_works_with_same_sizes); + static_assert(sizeof(TimeTicks) == sizeof(Time), + "TimeTicks and Time must be the same size"); std::vector<TestCase> cases; cases.push_back({reinterpret_cast<TestFunc>(&Time::Now), "Time::Now"}); cases.push_back({&TimeTicks::Now, "TimeTicks::Now"}); diff --git a/base/win/i18n.cc b/base/win/i18n.cc index 9e523a1..a26e274 100644 --- a/base/win/i18n.cc +++ b/base/win/i18n.cc @@ -32,8 +32,9 @@ const char *const kLanguageFunctionNames[] = { &kThreadLanguagesFunctionName[0] }; -COMPILE_ASSERT(NUM_FUNCTIONS == arraysize(kLanguageFunctionNames), - language_function_enum_and_names_out_of_sync); +static_assert(NUM_FUNCTIONS == arraysize(kLanguageFunctionNames), + "LanguageFunction enum and kLanguageFunctionNames array must be " + "kept in sync"); // Calls one of the MUI Get*PreferredUILanguages functions, placing the result // in |languages|. |function| identifies the function to call and |flags| is diff --git a/base/win/iat_patch_function.cc b/base/win/iat_patch_function.cc index 31659c6..be7c545b 100644 --- a/base/win/iat_patch_function.cc +++ b/base/win/iat_patch_function.cc @@ -67,8 +67,9 @@ bool InterceptEnumCallback(const base::win::PEImage& image, const char* module, } // portability check - COMPILE_ASSERT(sizeof(iat->u1.Function) == - sizeof(intercept_information->new_function), unknown_IAT_thunk_format); + static_assert( + sizeof(iat->u1.Function) == sizeof(intercept_information->new_function), + "unknown IAT thunk format"); // Patch the function. intercept_information->return_code = diff --git a/base/win/scoped_bstr.cc b/base/win/scoped_bstr.cc index 63ade0c..298318db 100644 --- a/base/win/scoped_bstr.cc +++ b/base/win/scoped_bstr.cc @@ -14,7 +14,7 @@ ScopedBstr::ScopedBstr(const char16* non_bstr) } ScopedBstr::~ScopedBstr() { - COMPILE_ASSERT(sizeof(ScopedBstr) == sizeof(BSTR), ScopedBstrSize); + static_assert(sizeof(ScopedBstr) == sizeof(BSTR), "ScopedBstrSize"); SysFreeString(bstr_); } diff --git a/base/win/scoped_comptr.h b/base/win/scoped_comptr.h index ade12fe..5ce60e2 100644 --- a/base/win/scoped_comptr.h +++ b/base/win/scoped_comptr.h @@ -43,8 +43,9 @@ class ScopedComPtr : public scoped_refptr<Interface> { ~ScopedComPtr() { // We don't want the smart pointer class to be bigger than the pointer // it wraps. - COMPILE_ASSERT(sizeof(ScopedComPtr<Interface, interface_id>) == - sizeof(Interface*), ScopedComPtrSize); + static_assert( + sizeof(ScopedComPtr<Interface, interface_id>) == sizeof(Interface*), + "ScopedComPtrSize"); } // Explicit Release() of the held object. Useful for reuse of the diff --git a/base/win/scoped_variant.cc b/base/win/scoped_variant.cc index 2cf2657..4a1ad90 100644 --- a/base/win/scoped_variant.cc +++ b/base/win/scoped_variant.cc @@ -12,7 +12,7 @@ namespace win { const VARIANT ScopedVariant::kEmptyVariant = {{{VT_EMPTY}}}; ScopedVariant::~ScopedVariant() { - COMPILE_ASSERT(sizeof(ScopedVariant) == sizeof(VARIANT), ScopedVariantSize); + static_assert(sizeof(ScopedVariant) == sizeof(VARIANT), "ScopedVariantSize"); ::VariantClear(&var_); } |