Commit d119a275 authored by Jisi Liu's avatar Jisi Liu

Merge pull request #621 from nico/staticass

Let GOOGLE_COMPILE_ASSERT use static_assert if available.
parents aba42edd 56a90a20
...@@ -113,12 +113,13 @@ struct CompileAssert { ...@@ -113,12 +113,13 @@ struct CompileAssert {
} // namespace internal } // namespace internal
#undef GOOGLE_COMPILE_ASSERT #undef GOOGLE_COMPILE_ASSERT
#if __cplusplus >= 201103L
#define GOOGLE_COMPILE_ASSERT(expr, msg) static_assert(expr, #msg)
#else
#define GOOGLE_COMPILE_ASSERT(expr, msg) \ #define GOOGLE_COMPILE_ASSERT(expr, msg) \
::google::protobuf::internal::CompileAssert<(bool(expr))> \ ::google::protobuf::internal::CompileAssert<(bool(expr))> \
msg[bool(expr) ? 1 : -1]; \ msg[bool(expr) ? 1 : -1]; \
(void)msg (void)msg
// Implementation details of COMPILE_ASSERT: // Implementation details of COMPILE_ASSERT:
// //
// - COMPILE_ASSERT works by defining an array type that has -1 // - COMPILE_ASSERT works by defining an array type that has -1
...@@ -159,6 +160,7 @@ struct CompileAssert { ...@@ -159,6 +160,7 @@ struct CompileAssert {
// //
// This is to avoid running into a bug in MS VC 7.1, which // This is to avoid running into a bug in MS VC 7.1, which
// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1. // causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
#endif // __cplusplus >= 201103L
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment