summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--system_wrappers/interface/compile_assert.h13
-rw-r--r--typedefs.h11
2 files changed, 21 insertions, 3 deletions
diff --git a/system_wrappers/interface/compile_assert.h b/system_wrappers/interface/compile_assert.h
index cdeaa567..46e40ac4 100644
--- a/system_wrappers/interface/compile_assert.h
+++ b/system_wrappers/interface/compile_assert.h
@@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-// Borrowed from Chromium's src/base/basictypes.h.
+// Borrowed from Chromium's src/base/macros.h.
#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_
#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_
@@ -31,13 +31,20 @@
// TODO(ajm): Hack to avoid multiple definitions until the base/ of webrtc and
// libjingle are merged.
#if !defined(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 {
};
#define COMPILE_ASSERT(expr, msg) \
- typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
-#endif // COMPILE_ASSERT
+ typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] ALLOW_UNUSED
+
+#endif // __cplusplus >= 201103L
+#endif // !defined(COMPILE_ASSERT)
// Implementation details of COMPILE_ASSERT:
//
diff --git a/typedefs.h b/typedefs.h
index d8977ff4..d9328c67 100644
--- a/typedefs.h
+++ b/typedefs.h
@@ -96,6 +96,17 @@ typedef unsigned __int64 uint64_t;
#define OVERRIDE
#endif
+// Annotate a variable indicating it's ok if the variable is not used.
+// (Typically used to silence a compiler warning when the assignment
+// is important for some other reason.)
+// Use like:
+// int x ALLOW_UNUSED = ...;
+#if defined(__GNUC__)
+#define ALLOW_UNUSED __attribute__((unused))
+#else
+#define ALLOW_UNUSED
+#endif
+
// Annotate a function indicating the caller must examine the return value.
// Use like:
// int foo() WARN_UNUSED_RESULT;