使用noexcept说明符,尾随返回类型语法失败?

0x4*_*2D2 3 c++ c++11

此代码按预期工作:

void f() noexcept {}
Run Code Online (Sandbox Code Playgroud)

但是以下失败了GCC 4.7.2中的错误:

auto f() -> void noexcept {}

// error: expected initializer before ‘noexcept’
Run Code Online (Sandbox Code Playgroud)

我读过的文章没有说过任何关于无法noexcept在训练返回类型中指定的内容.这是一个错误(并且已经在最新版本的GCC中得到修复)?或者这是否被标准明确禁止?

And*_*owl 10

这不是正确的语法.它应该是:

auto f() noexcept -> void { }
Run Code Online (Sandbox Code Playgroud)

根据C++ 11标准的8.4.1/2段:

D1(parameter-declaration-clause)cv-qualifier-seq(opt)

ref-qualifier(opt)*exception-specification(opt)*attribute-specifier-seq(opt)*trailing-return-type(opt)*

如8.3.5中所述.应仅在命名空间或类范围中定义函数.