This is a follow-up up of this question.
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.
That was fine, it made sense and that was all.
Then I came through [7.1.7.4.1/2] (placeholder type deduction) of the working draft.
There it is said that:
[...]
- for a non-discardedreturn
statement that occurs in a function declared with a return type that contains a placeholder type,T
is the declared return type ande
is the operand of thereturn
statement. If thereturn
statement has no operand, thene
isvoid{}
;
[...]
So, is void{}
(conceptually) legal or not?
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.
Otherwise, should the working draft use void()
instead of void{}
?
Well, to be honest, I'm quite sure I'm not skilled enough to point out an error in the working draft, so the real question is: what 's wrong in my reasoning?
What's exactly the void{}
mentioned in the bullet above and why it's a legal expression in this case?
Having no legal effect from the start. Thus, a void contract is invalid from the start of its purported closing (having no legal effect, it does not change the legal relationship between the parties involved).
In contract law, the term “null and void” means the contract was never valid. Therefore, the contract has no legal effect. This is different from having a contract invalidated. Contracts may be considered null and void for various reasons, generally because they're missing one or more of the elements discussed above.
A void contract is a contract that isn't legally enforceable, starting from the time it was created. While both a void and voidable contract are null, a void contract cannot be ratified. In a legal sense, a void contract is treated as if it was never created and becomes unenforceable in court.
A contract which is void ab initio is a contract which was invalid from its very inception. “Ab initio” is Latin for “from the beginning”, and is used to describe contracts which were legally unenforceable from the moment they were created.
To me it sounds like someone messed up merging the previous standard with the new one.
Previously the standard said this: (C++14 N4140, 7.1.6.4.7 [dcl.spec.auto]):
When a [...]
return
statement occurs in a function declared with a return type that contains a placeholder type, the deduced return type or variable type is determined from the type of its initializer. In the case of areturn
with no operand, the initializer is considered to bevoid()
.
The newer standard allows for if constexpr
statements, so the language needed to change to reflect that. if constexpr
leads to the concept of a potentially discarded return
statement (if the return
is in the not-taken branch of a constexpr if, then it's discarded and the return type is inferred from other return statements, if any).
Probably the new wording should be something like:
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 ande
is the operand of thereturn
statement. If the return statement has no operand, thenT
isauto
and the deduced return type isvoid
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With