From bb7c6eb7180a649af44634dee6e48331d1a71d13 Mon Sep 17 00:00:00 2001 From: viettrungluu Date: Mon, 6 Oct 2014 19:38:10 -0700 Subject: Mojo: Change MOJO_COMPILE_ASSERT -> static_assert in mojo/. Except under mojo/public/c/system, where we rename MOJO_COMPILE_ASSERT -> MOJO_STATIC_ASSERT and keep it around (but always use static_assert when compiling as C++). (We need to keep some macro around, since we want static assertions in headers that may be compiled as C.) R=sky@chromium.org Review URL: https://codereview.chromium.org/632743003 Cr-Commit-Position: refs/heads/master@{#298337} --- mojo/edk/system/options_validation_unittest.cc | 4 +-- mojo/public/c/system/buffer.h | 10 +++---- mojo/public/c/system/data_pipe.h | 6 ++-- mojo/public/c/system/macros.h | 15 +++------- mojo/public/c/system/message_pipe.h | 6 ++-- mojo/public/c/system/tests/macros_unittest.cc | 10 +++---- mojo/public/c/system/types.h | 6 ++-- mojo/public/cpp/bindings/lib/array_internal.h | 21 ++++++-------- mojo/public/cpp/bindings/lib/array_serialization.h | 33 ++++++++++------------ mojo/public/cpp/bindings/lib/bindings_internal.h | 10 +++---- mojo/public/cpp/bindings/lib/message_internal.h | 10 +++---- .../bindings/tests/validation_test_input_parser.cc | 4 +-- mojo/public/cpp/system/buffer.h | 10 +++---- mojo/public/cpp/system/data_pipe.h | 20 ++++++------- mojo/public/cpp/system/handle.h | 11 ++++---- mojo/public/cpp/system/message_pipe.h | 9 +++--- mojo/public/cpp/system/tests/macros_unittest.cc | 6 ++-- mojo/public/cpp/utility/mutex.h | 2 +- .../cpp_templates/params_definition.tmpl | 4 +-- .../cpp_templates/struct_declaration.tmpl | 4 +-- 20 files changed, 93 insertions(+), 108 deletions(-) diff --git a/mojo/edk/system/options_validation_unittest.cc b/mojo/edk/system/options_validation_unittest.cc index f410f24..89c4e60 100644 --- a/mojo/edk/system/options_validation_unittest.cc +++ b/mojo/edk/system/options_validation_unittest.cc @@ -18,14 +18,14 @@ namespace { typedef uint32_t TestOptionsFlags; -MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment); +static_assert(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); struct MOJO_ALIGNAS(8) TestOptions { uint32_t struct_size; TestOptionsFlags flags; uint32_t member1; uint32_t member2; }; -MOJO_COMPILE_ASSERT(sizeof(TestOptions) == 16, TestOptions_has_wrong_size); +static_assert(sizeof(TestOptions) == 16, "TestOptions has wrong size"); const uint32_t kSizeOfTestOptions = static_cast(sizeof(TestOptions)); diff --git a/mojo/public/c/system/buffer.h b/mojo/public/c/system/buffer.h index 19e3c52..97bc340 100644 --- a/mojo/public/c/system/buffer.h +++ b/mojo/public/c/system/buffer.h @@ -38,13 +38,13 @@ const MojoCreateSharedBufferOptionsFlags ((MojoCreateSharedBufferOptionsFlags)0) #endif -MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment); +MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); struct MOJO_ALIGNAS(8) MojoCreateSharedBufferOptions { uint32_t struct_size; MojoCreateSharedBufferOptionsFlags flags; }; -MOJO_COMPILE_ASSERT(sizeof(MojoCreateSharedBufferOptions) == 8, - MojoCreateSharedBufferOptions_has_wrong_size); +MOJO_STATIC_ASSERT(sizeof(MojoCreateSharedBufferOptions) == 8, + "MojoCreateSharedBufferOptions has wrong size"); // |MojoDuplicateBufferHandleOptions|: Used to specify parameters in duplicating // access to a shared buffer to |MojoDuplicateBufferHandle()|. @@ -71,8 +71,8 @@ struct MojoDuplicateBufferHandleOptions { uint32_t struct_size; MojoDuplicateBufferHandleOptionsFlags flags; }; -MOJO_COMPILE_ASSERT(sizeof(MojoDuplicateBufferHandleOptions) == 8, - MojoDuplicateBufferHandleOptions_has_wrong_size); +MOJO_STATIC_ASSERT(sizeof(MojoDuplicateBufferHandleOptions) == 8, + "MojoDuplicateBufferHandleOptions has wrong size"); // |MojoMapBufferFlags|: Used to specify different modes to |MojoMapBuffer()|. // |MOJO_MAP_BUFFER_FLAG_NONE| - No flags; default mode. diff --git a/mojo/public/c/system/data_pipe.h b/mojo/public/c/system/data_pipe.h index c8087ea..e4a15e9 100644 --- a/mojo/public/c/system/data_pipe.h +++ b/mojo/public/c/system/data_pipe.h @@ -46,15 +46,15 @@ const MojoCreateDataPipeOptionsFlags ((MojoCreateDataPipeOptionsFlags)1 << 0) #endif -MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment); +MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); struct MOJO_ALIGNAS(8) MojoCreateDataPipeOptions { uint32_t struct_size; MojoCreateDataPipeOptionsFlags flags; uint32_t element_num_bytes; uint32_t capacity_num_bytes; }; -MOJO_COMPILE_ASSERT(sizeof(MojoCreateDataPipeOptions) == 16, - MojoCreateDataPipeOptions_has_wrong_size); +MOJO_STATIC_ASSERT(sizeof(MojoCreateDataPipeOptions) == 16, + "MojoCreateDataPipeOptions has wrong size"); // |MojoWriteDataFlags|: Used to specify different modes to |MojoWriteData()| // and |MojoBeginWriteData()|. diff --git a/mojo/public/c/system/macros.h b/mojo/public/c/system/macros.h index 564ee60..dde65ff 100644 --- a/mojo/public/c/system/macros.h +++ b/mojo/public/c/system/macros.h @@ -43,18 +43,11 @@ inline void mojo_ignore_result(const T&) { // Assert things at compile time. (|msg| should be a valid identifier name.) // This macro is currently C++-only, but we want to use it in the C core.h. // Use like: -// MOJO_COMPILE_ASSERT(sizeof(Foo) == 12, Foo_has_invalid_size); -#if __cplusplus >= 201103L -#define MOJO_COMPILE_ASSERT(expr, msg) static_assert(expr, #msg) -#elif defined(__cplusplus) -namespace mojo { -template -struct CompileAssert {}; -} -#define MOJO_COMPILE_ASSERT(expr, msg) \ - typedef ::mojo::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] +// MOJO_STATIC_ASSERT(sizeof(Foo) == 12, "Foo has invalid size"); +#if defined(__cplusplus) +#define MOJO_STATIC_ASSERT(expr, msg) static_assert(expr, msg) #else -#define MOJO_COMPILE_ASSERT(expr, msg) +#define MOJO_STATIC_ASSERT(expr, msg) #endif // Like the C++11 |alignof| operator. diff --git a/mojo/public/c/system/message_pipe.h b/mojo/public/c/system/message_pipe.h index b08ba75..97d8887 100644 --- a/mojo/public/c/system/message_pipe.h +++ b/mojo/public/c/system/message_pipe.h @@ -31,13 +31,13 @@ const MojoCreateMessagePipeOptionsFlags ((MojoCreateMessagePipeOptionsFlags)0) #endif -MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment); +MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); struct MOJO_ALIGNAS(8) MojoCreateMessagePipeOptions { uint32_t struct_size; MojoCreateMessagePipeOptionsFlags flags; }; -MOJO_COMPILE_ASSERT(sizeof(MojoCreateMessagePipeOptions) == 8, - MojoCreateMessagePipeOptions_has_wrong_size); +MOJO_STATIC_ASSERT(sizeof(MojoCreateMessagePipeOptions) == 8, + "MojoCreateMessagePipeOptions has wrong size"); // |MojoWriteMessageFlags|: Used to specify different modes to // |MojoWriteMessage()|. diff --git a/mojo/public/c/system/tests/macros_unittest.cc b/mojo/public/c/system/tests/macros_unittest.cc index 6a694b8..d4292cf 100644 --- a/mojo/public/c/system/tests/macros_unittest.cc +++ b/mojo/public/c/system/tests/macros_unittest.cc @@ -34,14 +34,14 @@ TEST(MacrosTest, WarnUnusedResult) { abort(); } -// First test |MOJO_COMPILE_ASSERT()| in a global scope. -MOJO_COMPILE_ASSERT(sizeof(int64_t) == 2 * sizeof(int32_t), - bad_compile_assert_failure_in_global_scope); +// First test |MOJO_STATIC_ASSERT()| in a global scope. +MOJO_STATIC_ASSERT(sizeof(int64_t) == 2 * sizeof(int32_t), + "Bad static_assert() failure in global scope"); TEST(MacrosTest, CompileAssert) { // Then in a local scope. - MOJO_COMPILE_ASSERT(sizeof(int32_t) == 2 * sizeof(int16_t), - bad_compile_assert_failure); + MOJO_STATIC_ASSERT(sizeof(int32_t) == 2 * sizeof(int16_t), + "Bad static_assert() failure"); } TEST(MacrosTest, Alignof) { diff --git a/mojo/public/c/system/types.h b/mojo/public/c/system/types.h index 5a72d2f..96441dc 100644 --- a/mojo/public/c/system/types.h +++ b/mojo/public/c/system/types.h @@ -165,12 +165,12 @@ const MojoHandleSignals MOJO_HANDLE_SIGNAL_WRITABLE = 1 << 1; // TODO(vtl): Add out parameters with this to MojoWait/MojoWaitMany. // Note: This struct is not extensible (and only has 32-bit quantities), so it's // 32-bit-aligned. -MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int32_t) == 4, int32_t_has_weird_alignment); +MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int32_t) == 4, "int32_t has weird alignment"); struct MOJO_ALIGNAS(4) MojoHandleSignalsState { MojoHandleSignals satisfied_signals; MojoHandleSignals satisfiable_signals; }; -MOJO_COMPILE_ASSERT(sizeof(MojoHandleSignalsState) == 8, - MojoHandleSignalsState_has_wrong_size); +MOJO_STATIC_ASSERT(sizeof(MojoHandleSignalsState) == 8, + "MojoHandleSignalsState has wrong size"); #endif // MOJO_PUBLIC_C_SYSTEM_TYPES_H_ diff --git a/mojo/public/cpp/bindings/lib/array_internal.h b/mojo/public/cpp/bindings/lib/array_internal.h index 3681d8e..a94bae1 100644 --- a/mojo/public/cpp/bindings/lib/array_internal.h +++ b/mojo/public/cpp/bindings/lib/array_internal.h @@ -184,11 +184,10 @@ struct ArraySerializationHelper { static bool ValidateElements(const ArrayHeader* header, const ElementType* elements, BoundsChecker* bounds_checker) { - MOJO_COMPILE_ASSERT(!element_is_nullable, - Primitive_type_should_be_non_nullable); - MOJO_COMPILE_ASSERT( - (IsSame::value), - Primitive_type_should_not_have_array_validate_params); + static_assert(!element_is_nullable, + "Primitive type should be non-nullable"); + static_assert((IsSame::value), + "Primitive type should not have array validate params"); return true; } }; @@ -209,9 +208,8 @@ struct ArraySerializationHelper { static bool ValidateElements(const ArrayHeader* header, const ElementType* elements, BoundsChecker* bounds_checker) { - MOJO_COMPILE_ASSERT( - (IsSame::value), - Handle_type_should_not_have_array_validate_params); + static_assert((IsSame::value), + "Handle type should not have array validate params"); for (uint32_t i = 0; i < header->num_elements; ++i) { if (!element_is_nullable && @@ -307,9 +305,8 @@ struct ArraySerializationHelper { template struct ValidateCaller { static bool Run(const void* data, BoundsChecker* bounds_checker) { - MOJO_COMPILE_ASSERT( - (IsSame::value), - Struct_type_should_not_have_array_validate_params); + static_assert((IsSame::value), + "Struct type should not have array validate params"); return T::Validate(data, bounds_checker); } @@ -423,7 +420,7 @@ class Array_Data { // Elements of type internal::ArrayDataTraits::StorageType follow. }; -MOJO_COMPILE_ASSERT(sizeof(Array_Data) == 8, bad_sizeof_Array_Data); +static_assert(sizeof(Array_Data) == 8, "Bad sizeof(Array_Data)"); // UTF-8 encoded typedef Array_Data String_Data; diff --git a/mojo/public/cpp/bindings/lib/array_serialization.h b/mojo/public/cpp/bindings/lib/array_serialization.h index 4407de8..4f25135 100644 --- a/mojo/public/cpp/bindings/lib/array_serialization.h +++ b/mojo/public/cpp/bindings/lib/array_serialization.h @@ -37,18 +37,17 @@ template ::value> struct ArraySerializer; template struct ArraySerializer { - MOJO_COMPILE_ASSERT(sizeof(E) == sizeof(F), wrong_array_serializer); + static_assert(sizeof(E) == sizeof(F), "Incorrect array serializer"); static size_t GetSerializedSize(const Array& input) { return sizeof(Array_Data) + Align(input.size() * sizeof(E)); } template static void SerializeElements( Array input, Buffer* buf, Array_Data* output) { - MOJO_COMPILE_ASSERT(!element_is_nullable, - Primitive_type_should_be_non_nullable); - MOJO_COMPILE_ASSERT( - (IsSame::value), - Primitive_type_should_not_have_array_validate_params); + static_assert(!element_is_nullable, + "Primitive type should be non-nullable"); + static_assert((IsSame::value), + "Primitive type should not have array validate params"); memcpy(output->storage(), &input.storage()[0], input.size() * sizeof(E)); } @@ -67,11 +66,10 @@ template <> struct ArraySerializer { template static void SerializeElements( Array input, Buffer* buf, Array_Data* output) { - MOJO_COMPILE_ASSERT(!element_is_nullable, - Primitive_type_should_be_non_nullable); - MOJO_COMPILE_ASSERT( - (IsSame::value), - Primitive_type_should_not_have_array_validate_params); + static_assert(!element_is_nullable, + "Primitive type should be non-nullable"); + static_assert((IsSame::value), + "Primitive type should not have array validate params"); // TODO(darin): Can this be a memcpy somehow instead of a bit-by-bit copy? for (size_t i = 0; i < input.size(); ++i) @@ -95,9 +93,8 @@ template struct ArraySerializer, H, true> { static void SerializeElements(Array > input, Buffer* buf, Array_Data* output) { - MOJO_COMPILE_ASSERT( - (IsSame::value), - Handle_type_should_not_have_array_validate_params); + static_assert((IsSame::value), + "Handle type should not have array validate params"); for (size_t i = 0; i < input.size(); ++i) { output->at(i) = input[i].release(); // Transfer ownership of the handle. @@ -157,8 +154,8 @@ template struct ArraySerializer { template struct SerializeCaller { static void Run(T input, Buffer* buf, typename T::Data_** output) { - MOJO_COMPILE_ASSERT((IsSame::value), - Struct_type_should_not_have_array_validate_params); + static_assert((IsSame::value), + "Struct type should not have array validate params"); Serialize_(input.Pass(), buf, output); } @@ -187,10 +184,10 @@ template <> struct ArraySerializer { Array input, Buffer* buf, Array_Data* output) { - MOJO_COMPILE_ASSERT( + static_assert( (IsSame >::value), - String_type_has_unexpected_array_validate_params); + "String type has unexpected array validate params"); for (size_t i = 0; i < input.size(); ++i) { String_Data* element; diff --git a/mojo/public/cpp/bindings/lib/bindings_internal.h b/mojo/public/cpp/bindings/lib/bindings_internal.h index f12be10..251283f 100644 --- a/mojo/public/cpp/bindings/lib/bindings_internal.h +++ b/mojo/public/cpp/bindings/lib/bindings_internal.h @@ -20,33 +20,33 @@ struct StructHeader { uint32_t num_bytes; uint32_t num_fields; }; -MOJO_COMPILE_ASSERT(sizeof(StructHeader) == 8, bad_sizeof_StructHeader); +static_assert(sizeof(StructHeader) == 8, "Bad sizeof(StructHeader)"); struct ArrayHeader { uint32_t num_bytes; uint32_t num_elements; }; -MOJO_COMPILE_ASSERT(sizeof(ArrayHeader) == 8, bad_sizeof_ArrayHeader); +static_assert(sizeof(ArrayHeader) == 8, "Bad_sizeof(ArrayHeader)"); template union StructPointer { uint64_t offset; T* ptr; }; -MOJO_COMPILE_ASSERT(sizeof(StructPointer) == 8, bad_sizeof_StructPointer); +static_assert(sizeof(StructPointer) == 8, "Bad_sizeof(StructPointer)"); template union ArrayPointer { uint64_t offset; Array_Data* ptr; }; -MOJO_COMPILE_ASSERT(sizeof(ArrayPointer) == 8, bad_sizeof_ArrayPointer); +static_assert(sizeof(ArrayPointer) == 8, "Bad_sizeof(ArrayPointer)"); union StringPointer { uint64_t offset; Array_Data* ptr; }; -MOJO_COMPILE_ASSERT(sizeof(StringPointer) == 8, bad_sizeof_StringPointer); +static_assert(sizeof(StringPointer) == 8, "Bad_sizeof(StringPointer)"); #pragma pack(pop) diff --git a/mojo/public/cpp/bindings/lib/message_internal.h b/mojo/public/cpp/bindings/lib/message_internal.h index 3c67902..d9f07db 100644 --- a/mojo/public/cpp/bindings/lib/message_internal.h +++ b/mojo/public/cpp/bindings/lib/message_internal.h @@ -21,20 +21,20 @@ struct MessageHeader : internal::StructHeader { uint32_t name; uint32_t flags; }; -MOJO_COMPILE_ASSERT(sizeof(MessageHeader) == 16, bad_sizeof_MessageHeader); +static_assert(sizeof(MessageHeader) == 16, "Bad sizeof(MessageHeader)"); struct MessageHeaderWithRequestID : MessageHeader { uint64_t request_id; }; -MOJO_COMPILE_ASSERT(sizeof(MessageHeaderWithRequestID) == 24, - bad_sizeof_MessageHeaderWithRequestID); +static_assert(sizeof(MessageHeaderWithRequestID) == 24, + "Bad sizeof(MessageHeaderWithRequestID)"); struct MessageData { MessageHeader header; }; -MOJO_COMPILE_ASSERT(sizeof(MessageData) == sizeof(MessageHeader), - bad_sizeof_MessageData); +static_assert(sizeof(MessageData) == sizeof(MessageHeader), + "Bad sizeof(MessageData)"); #pragma pack(pop) diff --git a/mojo/public/cpp/bindings/tests/validation_test_input_parser.cc b/mojo/public/cpp/bindings/tests/validation_test_input_parser.cc index f5b5a01..20a1f06 100644 --- a/mojo/public/cpp/bindings/tests/validation_test_input_parser.cc +++ b/mojo/public/cpp/bindings/tests/validation_test_input_parser.cc @@ -275,7 +275,7 @@ bool ValidationTestInputParser::ParseSignedInteger( bool ValidationTestInputParser::ParseFloat( const DataType& type, const std::string& value_string) { - MOJO_COMPILE_ASSERT(sizeof(float) == 4, float_size_is_not_4); + static_assert(sizeof(float) == 4, "sizeof(float) is not 4"); float value; if (sscanf(value_string.c_str(), "%f", &value) != 1) @@ -287,7 +287,7 @@ bool ValidationTestInputParser::ParseFloat( bool ValidationTestInputParser::ParseDouble(const DataType& type, const std::string& value_string) { - MOJO_COMPILE_ASSERT(sizeof(double) == 8, double_size_is_not_8); + static_assert(sizeof(double) == 8, "sizeof(double) is not 8"); double value; if (sscanf(value_string.c_str(), "%lf", &value) != 1) diff --git a/mojo/public/cpp/system/buffer.h b/mojo/public/cpp/system/buffer.h index ad9966a..1f47fe2 100644 --- a/mojo/public/cpp/system/buffer.h +++ b/mojo/public/cpp/system/buffer.h @@ -23,13 +23,13 @@ class SharedBufferHandle : public Handle { // Copying and assignment allowed. }; -MOJO_COMPILE_ASSERT(sizeof(SharedBufferHandle) == sizeof(Handle), - bad_size_for_cpp_SharedBufferHandle); +static_assert(sizeof(SharedBufferHandle) == sizeof(Handle), + "Bad size for C++ SharedBufferHandle"); typedef ScopedHandleBase ScopedSharedBufferHandle; -MOJO_COMPILE_ASSERT(sizeof(ScopedSharedBufferHandle) == - sizeof(SharedBufferHandle), - bad_size_for_cpp_ScopedSharedBufferHandle); +static_assert(sizeof(ScopedSharedBufferHandle) == + sizeof(SharedBufferHandle), + "Bad size for C++ ScopedSharedBufferHandle"); inline MojoResult CreateSharedBuffer( const MojoCreateSharedBufferOptions* options, diff --git a/mojo/public/cpp/system/data_pipe.h b/mojo/public/cpp/system/data_pipe.h index b2f6e68..ed65cbc 100644 --- a/mojo/public/cpp/system/data_pipe.h +++ b/mojo/public/cpp/system/data_pipe.h @@ -23,13 +23,13 @@ class DataPipeProducerHandle : public Handle { // Copying and assignment allowed. }; -MOJO_COMPILE_ASSERT(sizeof(DataPipeProducerHandle) == sizeof(Handle), - bad_size_for_cpp_DataPipeProducerHandle); +static_assert(sizeof(DataPipeProducerHandle) == sizeof(Handle), + "Bad size for C++ DataPipeProducerHandle"); typedef ScopedHandleBase ScopedDataPipeProducerHandle; -MOJO_COMPILE_ASSERT(sizeof(ScopedDataPipeProducerHandle) == - sizeof(DataPipeProducerHandle), - bad_size_for_cpp_ScopedDataPipeProducerHandle); +static_assert(sizeof(ScopedDataPipeProducerHandle) == + sizeof(DataPipeProducerHandle), + "Bad size for C++ ScopedDataPipeProducerHandle"); class DataPipeConsumerHandle : public Handle { public: @@ -39,13 +39,13 @@ class DataPipeConsumerHandle : public Handle { // Copying and assignment allowed. }; -MOJO_COMPILE_ASSERT(sizeof(DataPipeConsumerHandle) == sizeof(Handle), - bad_size_for_cpp_DataPipeConsumerHandle); +static_assert(sizeof(DataPipeConsumerHandle) == sizeof(Handle), + "Bad size for C++ DataPipeConsumerHandle"); typedef ScopedHandleBase ScopedDataPipeConsumerHandle; -MOJO_COMPILE_ASSERT(sizeof(ScopedDataPipeConsumerHandle) == - sizeof(DataPipeConsumerHandle), - bad_size_for_cpp_ScopedDataPipeConsumerHandle); +static_assert(sizeof(ScopedDataPipeConsumerHandle) == + sizeof(DataPipeConsumerHandle), + "Bad size for C++ ScopedDataPipeConsumerHandle"); inline MojoResult CreateDataPipe( const MojoCreateDataPipeOptions* options, diff --git a/mojo/public/cpp/system/handle.h b/mojo/public/cpp/system/handle.h index 72b14c8..52558fc 100644 --- a/mojo/public/cpp/system/handle.h +++ b/mojo/public/cpp/system/handle.h @@ -111,9 +111,9 @@ class ScopedHandleBase { template static ScopedHandleBase From( ScopedHandleBase other) { - MOJO_COMPILE_ASSERT( + static_assert( sizeof(static_cast(static_cast(0))), - HandleType_is_not_a_subtype_of_PassedHandleType); + "HandleType is not a subtype of PassedHandleType"); return ScopedHandleBase( static_cast(other.release().value())); } @@ -185,13 +185,12 @@ class Handle { }; // Should have zero overhead. -MOJO_COMPILE_ASSERT(sizeof(Handle) == sizeof(MojoHandle), - bad_size_for_cpp_Handle); +static_assert(sizeof(Handle) == sizeof(MojoHandle), "Bad size for C++ Handle"); // The scoper should also impose no more overhead. typedef ScopedHandleBase ScopedHandle; -MOJO_COMPILE_ASSERT(sizeof(ScopedHandle) == sizeof(Handle), - bad_size_for_cpp_ScopedHandle); +static_assert(sizeof(ScopedHandle) == sizeof(Handle), + "Bad size for C++ ScopedHandle"); inline MojoResult Wait(Handle handle, MojoHandleSignals signals, diff --git a/mojo/public/cpp/system/message_pipe.h b/mojo/public/cpp/system/message_pipe.h index 7ef6314..9357409 100644 --- a/mojo/public/cpp/system/message_pipe.h +++ b/mojo/public/cpp/system/message_pipe.h @@ -23,13 +23,12 @@ class MessagePipeHandle : public Handle { // Copying and assignment allowed. }; -MOJO_COMPILE_ASSERT(sizeof(MessagePipeHandle) == sizeof(Handle), - bad_size_for_cpp_MessagePipeHandle); +static_assert(sizeof(MessagePipeHandle) == sizeof(Handle), + "Bad size for C++ MessagePipeHandle"); typedef ScopedHandleBase ScopedMessagePipeHandle; -MOJO_COMPILE_ASSERT(sizeof(ScopedMessagePipeHandle) == - sizeof(MessagePipeHandle), - bad_size_for_cpp_ScopedMessagePipeHandle); +static_assert(sizeof(ScopedMessagePipeHandle) == sizeof(MessagePipeHandle), + "Bad size for C++ ScopedMessagePipeHandle"); inline MojoResult CreateMessagePipe(const MojoCreateMessagePipeOptions* options, ScopedMessagePipeHandle* message_pipe0, diff --git a/mojo/public/cpp/system/tests/macros_unittest.cc b/mojo/public/cpp/system/tests/macros_unittest.cc index 49a8005..63f31c9 100644 --- a/mojo/public/cpp/system/tests/macros_unittest.cc +++ b/mojo/public/cpp/system/tests/macros_unittest.cc @@ -60,10 +60,10 @@ TEST(MacrosCppTest, DisallowCopyAndAssign) { y.NoOp(); } -// Test that |MOJO_ARRAYSIZE()| works in a |MOJO_COMPILE_ASSERT()|. +// Test that |MOJO_ARRAYSIZE()| works in a |static_assert()|. const int kGlobalArray[5] = { 1, 2, 3, 4, 5 }; -MOJO_COMPILE_ASSERT(MOJO_ARRAYSIZE(kGlobalArray) == 5u, - mojo_array_size_failed_in_compile_assert); +static_assert(MOJO_ARRAYSIZE(kGlobalArray) == 5u, + "MOJO_ARRAY_SIZE() failed in static_assert()"); TEST(MacrosCppTest, ArraySize) { double local_array[4] = { 6.7, 7.8, 8.9, 9.0 }; diff --git a/mojo/public/cpp/utility/mutex.h b/mojo/public/cpp/utility/mutex.h index 35611c2..4dc4aee 100644 --- a/mojo/public/cpp/utility/mutex.h +++ b/mojo/public/cpp/utility/mutex.h @@ -63,7 +63,7 @@ class MutexLock { }; // Catch bug where variable name is omitted (e.g., |MutexLock (&mu)|). -#define MutexLock(x) MOJO_COMPILE_ASSERT(0, mutex_lock_missing_variable_name); +#define MutexLock(x) static_assert(0, "MutexLock() missing variable name"); } // namespace mojo diff --git a/mojo/public/tools/bindings/generators/cpp_templates/params_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/params_definition.tmpl index 0b11047..5de77d3 100644 --- a/mojo/public/tools/bindings/generators/cpp_templates/params_definition.tmpl +++ b/mojo/public/tools/bindings/generators/cpp_templates/params_definition.tmpl @@ -29,5 +29,5 @@ class {{class_name}} { header_.num_fields = {{struct.packed.packed_fields|length}}; } }; -MOJO_COMPILE_ASSERT(sizeof({{class_name}}) == {{struct.packed|struct_size}}, - bad_sizeof_{{class_name}}); +static_assert(sizeof({{class_name}}) == {{struct.packed|struct_size}}, + "Bad sizeof({{class_name}})"); diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_declaration.tmpl index 60a6a9e..b206f20 100644 --- a/mojo/public/tools/bindings/generators/cpp_templates/struct_declaration.tmpl +++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_declaration.tmpl @@ -18,5 +18,5 @@ class {{class_name}} { {{class_name}}(); ~{{class_name}}(); // NOT IMPLEMENTED }; -MOJO_COMPILE_ASSERT(sizeof({{class_name}}) == {{struct.packed|struct_size}}, - bad_sizeof_{{class_name}}); +static_assert(sizeof({{class_name}}) == {{struct.packed|struct_size}}, + "Bad sizeof({{class_name}})"); -- cgit v1.1