Commit 39e335c7 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[base] Make USE a variadic template

This will allow for passing more than one variable. 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

Change-Id: I8f894d730bbcd195ed83705f98771994b4bc906f
Reviewed-on: https://chromium-review.googlesource.com/565561Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46527}
parent c77d9da4
...@@ -190,9 +190,8 @@ V8_INLINE Dest bit_cast(Source const& source) { ...@@ -190,9 +190,8 @@ V8_INLINE Dest bit_cast(Source const& source) {
// 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> template <typename... Ts>
inline void USE(T) { } inline void USE(Ts&&...) {}
#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