Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3187)

Unified Diff: base/basictypes.h

Issue 77343005: When using C++11, use static_assert to implement COMPILE_ASSERT (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git cl try Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/basictypes.h
diff --git a/base/basictypes.h b/base/basictypes.h
index 10275f998de09c3817c0be066a55bc8af9c2f865..e77d7b10f24d3b699c3ee8a5361cb4984dc43c64 100644
--- a/base/basictypes.h
+++ b/base/basictypes.h
@@ -9,6 +9,7 @@
#include <stddef.h> // For size_t
#include <string.h> // for memcpy
+#include "base/compiler_specific.h"
#include "base/port.h" // Types that only need exist on certain systems
#ifndef COMPILER_MSVC
@@ -215,13 +216,21 @@ inline To implicit_cast(From const &f) {
// the expression is false, most compilers will issue a warning/error
// containing the name of the variable.
+#undef COMPILE_ASSERT
+
+#if __cplusplus >= 201103L
+
+// Under C++11, just use static_assert.
+#define COMPILE_ASSERT(expr, msg) static_assert(expr, #msg)
+
+#else
+
template <bool>
struct CompileAssert {
};
-#undef COMPILE_ASSERT
#define COMPILE_ASSERT(expr, msg) \
- typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
+ typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] ALLOW_UNUSED
// Implementation details of COMPILE_ASSERT:
//
@@ -264,6 +273,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
// bit_cast<Dest,Source> is a template function that implements the
// equivalent of "*reinterpret_cast<Dest*>(&source)". We need this in
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698