summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandrew@webrtc.org <andrew@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2014-05-04 03:04:26 +0000
committerandrew@webrtc.org <andrew@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2014-05-04 03:04:26 +0000
commit66a2eaeabcc1d3179c2f018716af5850dfb24d7c (patch)
treeff2840ac06fdee365fca4a517eb7d64790fbab26
parent547a7cd04486df2eb7fe4f41766fe0685c4e9a83 (diff)
downloadwebrtc-66a2eaeabcc1d3179c2f018716af5850dfb24d7c.tar.gz
Add ALLOW_UNUSED and update COMPILE_ASSERT to Chromium's latest.
Fixes building with gcc 4.8. TBR=fdegans@google.com BUG=chromium:321833 Review URL: https://webrtc-codereview.appspot.com/12439004 git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@6050 4adac7df-926f-26a2-2b94-8c16560cd09d
-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;