void {}是否合法? [英] Is void{} legal or not?

查看:225
本文介绍了void {}是否合法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是这个问题的后续行动.
在评论和答案中不止一次地提到void{}既不是有效的type-id也不是有效的表达式.

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.

然后我通过 [7.1 .7.4.1/2] (占位符类型推断).
据说:

Then I came through [7.1.7.4.1/2] (placeholder type deduction) of the working draft.
There it is said that:

[...]
-对于在使用包含占位符类型的返回类型声明的函数中发生的未丢弃的return语句,T是声明的返回类型,ereturn语句的操作数.如果return语句没有操作数,则evoid{};
[...]

[...]
- 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{};
[...]

那么,void{}(从概念上来说)合法吗?
如果工作草案中所述是可以接受的(即使只是作为-,就像是-声明一样),则它实际上必须是合法的.举例来说,这意味着decltype(void{})也应该有效.
否则,工作草案应使用void()而不是void{}吗?

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{}?

好吧,老实说,我很确定我不够熟练,无法指出工作草案中的错误,所以 real 问题是:我的推理有什么问题?
上面的项目符号中提到的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?

推荐答案

已确认该错误.已修复.
此处是讨论(老实说).

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

因此,答案是-否,void{}不合法.
这是工作草案的措辞错误.

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

这篇关于void {}是否合法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆