尾随返回类型语法与noexcept说明符失败? [英] Trailing return-type syntax fails with noexcept specifier?

查看:712
本文介绍了尾随返回类型语法与noexcept说明符失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码可按预期工作:

  void f()noexcept {} 



但是以下操作失败,并在GCC 4.7.2中出现错误:

  auto f() - > void noexcept {} 

//错误:'noexcept'前的预期初始化程序

我读过的文章没有说在训练返回类型中不能指定 noexcept 。这是一个错误(并已被修复在最新版本的GCC)?或者这是标准明确禁止的?

解决方案

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

  auto f()noexcept  - > void {} 

C ++ 11标准的第8.4.1 / 2节:


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



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



。函数只能在命名空间或类作用域中定义。



This code work as expected:

void f() noexcept {}

But the following fails with an error in 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. Is this a bug (and had it been fixed in the newest version of 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:

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

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

as described in 8.3.5. A function shall be defined only in namespace or class scope.

这篇关于尾随返回类型语法与noexcept说明符失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆