此代码按预期工作:
void f() noexcept {}
但是以下失败并在GCC 4.7.2中出错:
auto f() -> void noexcept {}
// error: expected initializer before ‘noexcept’
我读过的文章没有说过任何关于无法在训练返回类型中指定noexcept
的内容。这是一个错误(并且已经在最新版本的GCC中得到修复)?或者这是否被标准明确禁止?
答案 0 :(得分:10)
这不是正确的语法。它应该是:
auto f() noexcept -> void { }
根据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)* < / p>
如8.3.5中所述。只应在命名空间或类范围内定义函数。