Skip to content

Commit

Permalink
Modify ALLOW_UNUSED to allow enabling unused local warnings on MSVC.
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
pkasting authored and Commit bot committed Oct 16, 2014
1 parent 74d6a7e commit 99867ef
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 23 deletions.
12 changes: 9 additions & 3 deletions base/compiler_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion base/logging_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ TEST_F(LoggingTest, DcheckReleaseBehavior) {
// 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) {
Expand Down
8 changes: 4 additions & 4 deletions base/mac/foundation_util_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,12 @@
#endif // defined(ARCH_CPU_64_BITS)

NSInteger some_nsinteger;
FormatNSIntegerAsType* pointer_to_some_nsinteger ALLOW_UNUSED =
&some_nsinteger;
FormatNSIntegerAsType* pointer_to_some_nsinteger = &some_nsinteger;
ALLOW_UNUSED_LOCAL(pointer_to_some_nsinteger);

NSUInteger some_nsuinteger;
FormatNSUIntegerAsType* pointer_to_some_nsuinteger ALLOW_UNUSED =
&some_nsuinteger;
FormatNSUIntegerAsType* pointer_to_some_nsuinteger = &some_nsuinteger;
ALLOW_UNUSED_LOCAL(pointer_to_some_nsuinteger);

// Check that format specifier works correctly for NSInteger.
const struct {
Expand Down
3 changes: 2 additions & 1 deletion base/tuple_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ struct Addz {
} // 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);
Expand Down
12 changes: 8 additions & 4 deletions cc/quads/draw_quad_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,17 @@ void CompareDrawQuad(DrawQuad* quad,
#define QUAD_DATA \
gfx::Rect quad_rect(30, 40, 50, 60); \
gfx::Rect quad_visible_rect(40, 50, 30, 20); \
gfx::Rect ALLOW_UNUSED quad_opaque_rect(60, 55, 10, 10); \
bool ALLOW_UNUSED needs_blending = true;
gfx::Rect quad_opaque_rect( 60, 55, 10, 10); \
ALLOW_UNUSED_LOCAL(quad_opaque_rect); \
bool needs_blending = true; \
ALLOW_UNUSED_LOCAL(needs_blending);

#define SETUP_AND_COPY_QUAD_NEW(Type, quad) \
DrawQuad* copy_new = \
render_pass->CopyFromAndAppendDrawQuad(quad_new, copy_shared_state); \
CompareDrawQuad(quad_new, copy_new, copy_shared_state); \
const Type* ALLOW_UNUSED copy_quad = Type::MaterialCast(copy_new);
const Type* copy_quad = Type::MaterialCast(copy_new); \
ALLOW_UNUSED_LOCAL(copy_quad);

#define SETUP_AND_COPY_QUAD_ALL(Type, quad) \
DrawQuad* copy_all = \
Expand All @@ -124,7 +127,8 @@ void CompareDrawQuad(DrawQuad* quad,
DrawQuad* copy_new = render_pass->CopyFromAndAppendRenderPassDrawQuad( \
quad_new, copy_shared_state, a); \
CompareDrawQuad(quad_new, copy_new, copy_shared_state); \
const Type* ALLOW_UNUSED copy_quad = Type::MaterialCast(copy_new);
const Type* copy_quad = Type::MaterialCast(copy_new); \
ALLOW_UNUSED_LOCAL(copy_quad);

#define SETUP_AND_COPY_QUAD_ALL_RP(Type, quad, a) \
DrawQuad* copy_all = render_pass->CopyFromAndAppendRenderPassDrawQuad( \
Expand Down
12 changes: 6 additions & 6 deletions ipc/ipc_message_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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) \
Expand Down
2 changes: 1 addition & 1 deletion ppapi/proxy/dispatch_reply_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void DispatchResourceReplyOrDefaultParams(
// unused variables or other errors if they're used with these macros.
#define PPAPI_BEGIN_MESSAGE_MAP(class_name, msg) \
{ \
typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED; \
typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED_TYPE; \
const IPC::Message& ipc_message__ = msg; \
switch (ipc_message__.type()) { \

Expand Down
7 changes: 4 additions & 3 deletions ui/gl/generate_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1521,9 +1521,10 @@ def WriteFuncBinding(file, known_as, version_name):
# on the extension string or the GL version.
file.write("""void Driver%s::InitializeDynamicBindings(GLContext* context) {
DCHECK(context && context->IsCurrent(NULL));
const GLVersionInfo* ver ALLOW_UNUSED = context->GetVersionInfo();
std::string extensions ALLOW_UNUSED = context->GetExtensions();
extensions += " ";
const GLVersionInfo* ver = context->GetVersionInfo();
ALLOW_UNUSED_LOCAL(ver);
std::string extensions = context->GetExtensions() + " ";
ALLOW_UNUSED_LOCAL(extensions);
""" % set_name.upper())
for extension in sorted(used_extensions):
Expand Down

0 comments on commit 99867ef

Please sign in to comment.