Changes to ALLOW_UNUSED to match upcoming changes to the Chromium trunk:

* Eliminate usage of ALLOW_UNUSED to define COMPILE_ASSERT and just use
  static_assert() in all cases now that all platforms build with C++11.
* Convert remaining uses of ALLOW_UNUSED to ALLOW_UNUSED_TYPE to match how
  Chromium will be splitting this functionality.  (In Chromium we'll have both
  ALLOW_UNUSED_TYPE and ALLOW_UNUSED_LOCAL, which have different syntax to
  enable us to use these with MSVC.)

BUG=chromium:81439
TEST=none
LOG=y
R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/613143004

Patch from Peter Kasting <pkasting@chromium.org>.

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24344 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
svenpanne@chromium.org 2014-10-01 06:32:05 +00:00
parent 1659197f5d
commit 356d668d8f
3 changed files with 49 additions and 61 deletions

View File

@ -7,15 +7,13 @@
#include "include/v8config.h" #include "include/v8config.h"
// Annotate a variable indicating it's ok if the variable is not used. // Annotate a typedef or function indicating it's ok if it's not used.
// (Typically used to silence a compiler warning when the assignment
// is important for some other reason.)
// Use like: // Use like:
// int x ALLOW_UNUSED = ...; // typedef Foo Bar ALLOW_UNUSED_TYPE;
#if V8_HAS_ATTRIBUTE_UNUSED #if V8_HAS_ATTRIBUTE_UNUSED
#define ALLOW_UNUSED __attribute__((unused)) #define ALLOW_UNUSED_TYPE __attribute__((unused))
#else #else
#define ALLOW_UNUSED #define ALLOW_UNUSED_TYPE
#endif #endif

View File

@ -64,42 +64,44 @@ class Flags FINAL {
}; };
#define DEFINE_OPERATORS_FOR_FLAGS(Type) \ #define DEFINE_OPERATORS_FOR_FLAGS(Type) \
inline Type operator&(Type::flag_type lhs, \ inline Type operator&( \
Type::flag_type rhs)ALLOW_UNUSED WARN_UNUSED_RESULT; \ Type::flag_type lhs, \
inline Type operator&(Type::flag_type lhs, Type::flag_type rhs) { \ Type::flag_type rhs)ALLOW_UNUSED_TYPE WARN_UNUSED_RESULT; \
return Type(lhs) & rhs; \ inline Type operator&(Type::flag_type lhs, Type::flag_type rhs) { \
} \ return Type(lhs) & rhs; \
inline Type operator&(Type::flag_type lhs, \ } \
const Type& rhs)ALLOW_UNUSED WARN_UNUSED_RESULT; \ inline Type operator&(Type::flag_type lhs, \
inline Type operator&(Type::flag_type lhs, const Type& rhs) { \ const Type& rhs)ALLOW_UNUSED_TYPE WARN_UNUSED_RESULT; \
return rhs & lhs; \ inline Type operator&(Type::flag_type lhs, const Type& rhs) { \
} \ return rhs & lhs; \
inline void operator&(Type::flag_type lhs, Type::mask_type rhs)ALLOW_UNUSED; \ } \
inline void operator&(Type::flag_type lhs, Type::mask_type rhs) {} \ inline void operator&(Type::flag_type lhs, \
inline Type operator|(Type::flag_type lhs, Type::flag_type rhs) \ Type::mask_type rhs)ALLOW_UNUSED_TYPE; \
ALLOW_UNUSED WARN_UNUSED_RESULT; \ inline void operator&(Type::flag_type lhs, Type::mask_type rhs) {} \
inline Type operator|(Type::flag_type lhs, Type::flag_type rhs) { \ inline Type operator|(Type::flag_type lhs, Type::flag_type rhs) \
return Type(lhs) | rhs; \ ALLOW_UNUSED_TYPE WARN_UNUSED_RESULT; \
} \ inline Type operator|(Type::flag_type lhs, Type::flag_type rhs) { \
inline Type operator|(Type::flag_type lhs, const Type& rhs) \ return Type(lhs) | rhs; \
ALLOW_UNUSED WARN_UNUSED_RESULT; \ } \
inline Type operator|(Type::flag_type lhs, const Type& rhs) { \ inline Type operator|(Type::flag_type lhs, const Type& rhs) \
return rhs | lhs; \ ALLOW_UNUSED_TYPE WARN_UNUSED_RESULT; \
} \ inline Type operator|(Type::flag_type lhs, const Type& rhs) { \
inline void operator|(Type::flag_type lhs, Type::mask_type rhs) \ return rhs | lhs; \
ALLOW_UNUSED; \ } \
inline void operator|(Type::flag_type lhs, Type::mask_type rhs) {} \ inline void operator|(Type::flag_type lhs, Type::mask_type rhs) \
inline Type operator^(Type::flag_type lhs, Type::flag_type rhs) \ ALLOW_UNUSED_TYPE; \
ALLOW_UNUSED WARN_UNUSED_RESULT; \ inline void operator|(Type::flag_type lhs, Type::mask_type rhs) {} \
inline Type operator^(Type::flag_type lhs, Type::flag_type rhs) { \ inline Type operator^(Type::flag_type lhs, Type::flag_type rhs) \
return Type(lhs) ^ rhs; \ ALLOW_UNUSED_TYPE WARN_UNUSED_RESULT; \
} inline Type operator^(Type::flag_type lhs, const Type& rhs) \ inline Type operator^(Type::flag_type lhs, Type::flag_type rhs) { \
ALLOW_UNUSED WARN_UNUSED_RESULT; \ return Type(lhs) ^ rhs; \
inline Type operator^(Type::flag_type lhs, const Type& rhs) { \ } inline Type operator^(Type::flag_type lhs, const Type& rhs) \
return rhs ^ lhs; \ ALLOW_UNUSED_TYPE WARN_UNUSED_RESULT; \
} inline void operator^(Type::flag_type lhs, Type::mask_type rhs) \ inline Type operator^(Type::flag_type lhs, const Type& rhs) { \
ALLOW_UNUSED; \ return rhs ^ lhs; \
} inline void operator^(Type::flag_type lhs, Type::mask_type rhs) \
ALLOW_UNUSED_TYPE; \
inline void operator^(Type::flag_type lhs, Type::mask_type rhs) {} inline void operator^(Type::flag_type lhs, Type::mask_type rhs) {}
} // namespace base } // namespace base

View File

@ -130,7 +130,7 @@ struct CompileAssert {};
#define COMPILE_ASSERT(expr, msg) \ #define COMPILE_ASSERT(expr, msg) \
typedef CompileAssert<static_cast<bool>(expr)> \ typedef CompileAssert<static_cast<bool>(expr)> \
msg[static_cast<bool>(expr) ? 1 : -1] ALLOW_UNUSED msg[static_cast<bool>(expr) ? 1 : -1] ALLOW_UNUSED_TYPE
// Implementation details of COMPILE_ASSERT: // Implementation details of COMPILE_ASSERT:
// //
@ -150,23 +150,11 @@ struct CompileAssert {};
// COMPILE_ASSERT(foo, msg); // not supposed to compile as foo is // COMPILE_ASSERT(foo, msg); // not supposed to compile as foo is
// // not a compile-time constant. // // not a compile-time constant.
// //
// - By using the type CompileAssert<(bool(expr))>, we ensures that // - By using the type CompileAssert<static_cast<bool>(expr)>, we ensure that
// expr is a compile-time constant. (Template arguments must be // expr is a compile-time constant. (Template arguments must be
// determined at compile-time.) // determined at compile-time.)
// //
// - The outer parentheses in CompileAssert<(bool(expr))> are necessary // - The array size is (static_cast<bool>(expr) ? 1 : -1), instead of simply
// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written
//
// CompileAssert<bool(expr)>
//
// instead, these compilers will refuse to compile
//
// COMPILE_ASSERT(5 > 0, some_message);
//
// (They seem to think the ">" in "5 > 0" marks the end of the
// template argument list.)
//
// - The array size is (bool(expr) ? 1 : -1), instead of simply
// //
// ((expr) ? 1 : -1). // ((expr) ? 1 : -1).
// //
@ -308,10 +296,10 @@ template <> class StaticAssertion<true> { };
// actually causes each use to introduce a new defined type with a // actually causes each use to introduce a new defined type with a
// name depending on the source line. // name depending on the source line.
template <int> class StaticAssertionHelper { }; template <int> class StaticAssertionHelper { };
#define STATIC_ASSERT(test) \ #define STATIC_ASSERT(test) \
typedef \ typedef StaticAssertionHelper< \
StaticAssertionHelper<sizeof(StaticAssertion<static_cast<bool>((test))>)> \ sizeof(StaticAssertion<static_cast<bool>((test))>)> \
SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__) ALLOW_UNUSED SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__) ALLOW_UNUSED_TYPE
#endif #endif