Skip to content

Commit

Permalink
Merge pull request protocolbuffers#621 from nico/staticass
Browse files Browse the repository at this point in the history
Let GOOGLE_COMPILE_ASSERT use static_assert if available.
  • Loading branch information
liujisi committed Jul 21, 2015
2 parents aba42ed + 56a90a2 commit d119a27
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/google/protobuf/stubs/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ struct CompileAssert {
} // namespace internal

#undef GOOGLE_COMPILE_ASSERT
#if __cplusplus >= 201103L
#define GOOGLE_COMPILE_ASSERT(expr, msg) static_assert(expr, #msg)
#else
#define GOOGLE_COMPILE_ASSERT(expr, msg) \
::google::protobuf::internal::CompileAssert<(bool(expr))> \
msg[bool(expr) ? 1 : -1]; \
(void)msg


// Implementation details of COMPILE_ASSERT:
//
// - COMPILE_ASSERT works by defining an array type that has -1
Expand Down Expand Up @@ -159,6 +160,7 @@ struct CompileAssert {
//
// This is to avoid running into a bug in MS VC 7.1, which
// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
#endif // __cplusplus >= 201103L

} // namespace protobuf
} // namespace google
Expand Down

0 comments on commit d119a27

Please sign in to comment.