I was given a piece of code that uses void()
as an argument. The code doesn\'t compile... obviously?
Can we instantiate anything of type void
The expression void()
is a prvalue of type void
and can be used anywhere such an expression may be used, which [basic.fundamental]/9 helpfully provides a list:
void();
true ? throw 1 : void()
++it1, void(), ++it2
decltype
or noexcept
: using my_void = decltype(void()); static_assert(noexcept(void()), "WAT");
return
statement of a function returning (possibly cv-qualified) void
: const void f() { return void(); }
void
: static_cast(void())
An expression of type void
can also be used as the operand of typeid
, but void()
in particular would be parsed as a type, not an expression, in this context.