简体   繁体   English

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

[英]Trailing return-type syntax fails with noexcept specifier?

This code work as expected: 此代码按预期工作:

void f() noexcept {}

But the following fails with an error in GCC 4.7.2: 但是以下失败了GCC 4.7.2中的错误:

auto f() -> void noexcept {}

// error: expected initializer before ‘noexcept’

Articles I've read haven't said anything about not being able to specify noexcept in a training return-type. 我读过的文章没有说过在训练返回类型中无法指定noexcept任何内容。 Is this a bug (and had it been fixed in the newest version of GCC)? 这是一个错误(并且已经在最新版本的GCC中得到修复)? Or is this prohibited explicitly by the Standard? 或者这是否被标准明确禁止?

That is not the correct syntax. 这不是正确的语法。 It should be: 它应该是:

auto f() noexcept -> void { }

Per paragraph 8.4.1/2 of the C++11 Standard: 根据C ++ 11标准的第8.4.1 / 2段:

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

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

as described in 8.3.5. 如8.3.5中所述。 A function shall be defined only in namespace or class scope. 应仅在命名空间或类范围中定义函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM