void foo(int unused) {
(void)unused;
}
or alternatively, in situations like: template<class T>
typename std::enable_if<((void)sizeof(T), true)>::type foo(T &&);
Edit:Also note that static_cast isn't quite like a function call, because it does something a function call does not, which is to extend the lifetime of the temporary it's operating on.
To see the difference, try replacing static_cast here with static_cast_:
#include <stdio.h>
struct B { };
struct S : B {
~S() { printf("~S(): %p\n", static_cast<void *>(this)); }
S() { printf("S(): %p\n", static_cast<void *>(this)); }
S(const S &) { printf("S(const S &): %p\n", static_cast<void *>(this)); }
S &operator =(const S &) { printf("S &operator =(const S &): %p\n", static_cast<void *>(this)); return *this; }
};
static S foo() { return S(); }
template<class To, class From>
To static_cast_(const From &v) { return static_cast<To>(v); }
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
const B &b = static_cast<const B &>(foo());
printf("Middle: %p\n", static_cast<const void *>(&b));
(void)b;
}
The compiler "sees through" the cast to extend the lifetime of the object returned by foo(), which produces different output.