Commit 69e7be85 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[base] Accept several values for USE

This CL changes the USE macro to accept more than one parameter.
This is particularly interesting for calling a method on each type in a
parameter pack, as in:

template<typename... T>
void foo(T&&... ts) {
  USE(do_something(ts)...);
}

Drive-by fix: Allow to pass arbitrary types to USE, including
references. This might prevent a copy for pass-by-value.

R=ishell@chromium.org, tebbi@chromium.org

Also-by: tebbi@chromium.org
Change-Id: I544e83bb996aaa638e7512295973dd3e742254bc
Reviewed-on: https://chromium-review.googlesource.com/567507Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46626}
parent 7d02925e
...@@ -188,11 +188,18 @@ V8_INLINE Dest bit_cast(Source const& source) { ...@@ -188,11 +188,18 @@ V8_INLINE Dest bit_cast(Source const& source) {
#define IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable<T>::value #define IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable<T>::value
#endif #endif
// The USE(x) template is used to silence C++ compiler warnings // The USE(x, ...) template is used to silence C++ compiler warnings
// issued for (yet) unused variables (typically parameters). // issued for (yet) unused variables (typically parameters).
template <typename T> // The arguments are guaranteed to be evaluated from left to right.
inline void USE(T) { } struct Use {
template <typename T>
Use(T&&) {} // NOLINT(runtime/explicit)
};
#define USE(...) \
do { \
::Use unused_tmp_array_for_use_macro[]{__VA_ARGS__}; \
(void)unused_tmp_array_for_use_macro; \
} while (false)
#define IS_POWER_OF_TWO(x) ((x) != 0 && (((x) & ((x) - 1)) == 0)) #define IS_POWER_OF_TWO(x) ((x) != 0 && (((x) & ((x) - 1)) == 0))
......
...@@ -154,7 +154,8 @@ class MemoryAllocationPermissionsTest : public ::testing::Test { ...@@ -154,7 +154,8 @@ class MemoryAllocationPermissionsTest : public ::testing::Test {
if (!sigsetjmp(continuation_, save_sigs)) { if (!sigsetjmp(continuation_, save_sigs)) {
switch (action) { switch (action) {
case MemoryAction::kRead: { case MemoryAction::kRead: {
USE(*buffer); // static_cast to remove the reference and force a memory read.
USE(static_cast<int>(*buffer));
break; break;
} }
case MemoryAction::kWrite: { case MemoryAction::kWrite: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment