c++language-lawyervoidc++17return-type-deduction

Is void{} legal or not?


This is a follow-up up of Differences between decltype(void()) and decltype(void{}).

In the comments and in the answer it is said more than once that void{} is neither a valid type-id nor a valid expression.

However, I came through [7.1.7.4.1/2] (placeholder type deduction) of the working draft, which says:

[...]

  • for a non-discarded return statement that occurs in a function declared with a return type that contains a placeholder type, T is the declared return type and e is the operand of the return statement. If the return statement has no operand, then e is void{};
    [...]

So, is void{} (conceptually) legal, or should the working draft use void()?

If it's acceptable as mentioned in the working draft (even though only as an - as if it's a - statement), it must be legal indeed. This means that decltype(void{}) should be valid as well, as an example.

Is there anything wrong with my reasoning? What exactly is the void{} mentioned in the bullet above and why is it a legal expression in this case?


Solution

  • Confirmed the bug. Already fixed.
    Here is the discussion (pretty short to be honest).

    So, the answer is - no, void{} is not legal.
    It was a wording bug of the working draft.