return 类型的匿名结构

Anonymous struct as a return type

下面的代码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(标志:-std=c++11 -Wall -Wextra -Werror -pedantic-errors)。它是 vc++ 中的错误吗?标准是否禁止此类构造?

struct
{
}
foo()
{
    return {};
}

int main()
{
}

MSVC 出现错误:

[dcl.fct]/9 Types shall not be defined in return or parameter types...

可以return匿名类型,但必须在函数内部定义:

auto foo()
{
    struct {} s;
    return s;
}