匿名结构作为返回类型 [英] Anonymous struct as a return type
问题描述
以下代码 使用 vc++ 19.00.23506 编译正常(标志:/Wall/WX/Za
) 和 vc++ 19.10.25109.0 (flags: /Wall/WX/Za/permissive-
, 这可以检查在 http://webcompiler.cloudapp.net),但是 不能用 clang 3.8.0 和 g++ 6.3.0 编译(标志:-std=c++11 -Wall -Wextra -Werror -pedantic-errors
).它是 vc++ 中的错误吗?标准是否禁止这种结构?
The following code compiles fine with vc++ 19.00.23506 (flags: /Wall /WX /Za
) and with vc++ 19.10.25109.0 (flags: /Wall /WX /Za /permissive-
, this can be checked at http://webcompiler.cloudapp.net), but doesn't compile with clang 3.8.0 and g++ 6.3.0 (flags: -std=c++11 -Wall -Wextra -Werror -pedantic-errors
). Is it a bug in vc++ and does the standard prohibit such constructions?
struct
{
}
foo()
{
return {};
}
int main()
{
}
推荐答案
MSVC 出现错误:
[dcl.fct]/9 不应在返回或参数类型中定义类型...
[dcl.fct]/9 Types shall not be defined in return or parameter types...
这篇关于匿名结构作为返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!