Modify ALLOW_UNUSED to allow enabling unused local warnings on MSVC.
This splits the macro into two:
int a = 1;
ALLOW_UNUSED_LOCAL(a);
and
typedef Foo Bar ALLOW_UNUSED_TYPE;
void foo() ALLOW_UNUSED_TYPE; // ALLOW_UNUSED_TYPE_OR_FUNC seemed too verbose
This matches changes that have already been made in Blink.
BUG=81439
TEST=none
TBR=ben
Review URL: https://codereview.chromium.org/650393002
Cr-Commit-Position: refs/heads/master@{#300014}
CrOS-Libchrome-Original-Commit: 99867ef78bf14ad37e263860248d0a2d61b51a73
diff --git a/base/compiler_specific.h b/base/compiler_specific.h
index ba57cc3..6210d1a 100644
--- a/base/compiler_specific.h
+++ b/base/compiler_specific.h
@@ -94,11 +94,17 @@
// (Typically used to silence a compiler warning when the assignment
// is important for some other reason.)
// Use like:
-// int x ALLOW_UNUSED = ...;
+// int x = ...;
+// ALLOW_UNUSED_LOCAL(x);
+#define ALLOW_UNUSED_LOCAL(x) false ? (void)x : (void)0
+
+// Annotate a typedef or function indicating it's ok if it's not used.
+// Use like:
+// typedef Foo Bar ALLOW_UNUSED_TYPE;
#if defined(COMPILER_GCC)
-#define ALLOW_UNUSED __attribute__((unused))
+#define ALLOW_UNUSED_TYPE __attribute__((unused))
#else
-#define ALLOW_UNUSED
+#define ALLOW_UNUSED_TYPE
#endif
// Annotate a function indicating it should not be inlined.
diff --git a/base/logging_unittest.cc b/base/logging_unittest.cc
index 6ebe32e..95a16f2 100644
--- a/base/logging_unittest.cc
+++ b/base/logging_unittest.cc
@@ -240,7 +240,8 @@
// looking in the global namespace.
namespace nested_test {
class Streamable {};
- ALLOW_UNUSED std::ostream& operator<<(std::ostream& out, const Streamable&) {
+ ALLOW_UNUSED_TYPE std::ostream& operator<<(std::ostream& out,
+ const Streamable&) {
return out << "Streamable";
}
TEST_F(LoggingTest, StreamingWstringFindsCorrectOperator) {
diff --git a/base/tuple_unittest.cc b/base/tuple_unittest.cc
index 402394c..8d620de 100644
--- a/base/tuple_unittest.cc
+++ b/base/tuple_unittest.cc
@@ -30,7 +30,8 @@
} // namespace
TEST(TupleTest, Basic) {
- Tuple0 t0 ALLOW_UNUSED = MakeTuple();
+ Tuple0 t0 = MakeTuple();
+ ALLOW_UNUSED_LOCAL(t0);
Tuple1<int> t1(1);
Tuple2<int, const char*> t2 = MakeTuple(1, static_cast<const char*>("wee"));
Tuple3<int, int, int> t3(1, 2, 3);
diff --git a/ipc/ipc_message_macros.h b/ipc/ipc_message_macros.h
index e38ef28..0978765 100644
--- a/ipc/ipc_message_macros.h
+++ b/ipc/ipc_message_macros.h
@@ -892,7 +892,7 @@
#define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \
{ \
- typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED; \
+ typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED_TYPE; \
void* param__ = NULL; \
const IPC::Message& ipc_message__ = msg; \
switch (ipc_message__.type()) {
@@ -905,11 +905,11 @@
#define IPC_DECLTYPE typeof
#endif
-#define IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(class_name, msg, param) \
- { \
- typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED; \
- IPC_DECLTYPE(param) param__ = param; \
- const IPC::Message& ipc_message__ = msg; \
+#define IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(class_name, msg, param) \
+ { \
+ typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED_TYPE; \
+ IPC_DECLTYPE(param) param__ = param; \
+ const IPC::Message& ipc_message__ = msg; \
switch (ipc_message__.type()) {
#define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \