The following code example seems to compile with GCC 12.2, in contrast to Clang 15 and MSVC 19.33, due to an error illegal initializer type 'void'
. I would expect the code to be rejected by all three compilers, as it doesn't make sense to construct a (temporary) void object.
auto f() { return void{}; }
using t = decltype(f());
In the example, function f
is only used with an unevaluated operand. Is it allowed to use f
like this or should even its definition be rejected? (I'm aware of the legal expression void()
which creates a prvalue instead, but it's besides the point of this post.)
Passages from the standard that seem relevant:
Incompletely-defined object types and cv void are incomplete types ([basic.fundamental]).
The size and layout of an instance of an incompletely-defined object type is unknown.