diff options
author | viettrungluu <viettrungluu@chromium.org> | 2014-10-06 19:38:10 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-07 02:38:48 +0000 |
commit | bb7c6eb7180a649af44634dee6e48331d1a71d13 (patch) | |
tree | 32b019c6ea663f585b57bb7a2740fcd3ccbab23b /mojo/public/c | |
parent | c79e745f391651a7e79b2499c27789fdfbd49a5d (diff) | |
download | chromium_src-bb7c6eb7180a649af44634dee6e48331d1a71d13.zip chromium_src-bb7c6eb7180a649af44634dee6e48331d1a71d13.tar.gz chromium_src-bb7c6eb7180a649af44634dee6e48331d1a71d13.tar.bz2 |
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}
Diffstat (limited to 'mojo/public/c')
-rw-r--r-- | mojo/public/c/system/buffer.h | 10 | ||||
-rw-r--r-- | mojo/public/c/system/data_pipe.h | 6 | ||||
-rw-r--r-- | mojo/public/c/system/macros.h | 15 | ||||
-rw-r--r-- | mojo/public/c/system/message_pipe.h | 6 | ||||
-rw-r--r-- | mojo/public/c/system/tests/macros_unittest.cc | 10 | ||||
-rw-r--r-- | mojo/public/c/system/types.h | 6 |
6 files changed, 23 insertions, 30 deletions
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 <bool> -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_ |