由于noexcept说明符,尾随返回类型语法失败
Trailing return-type syntax fails with noexcept specifier?
代码正常运行:
void f() noexcept {}
但是下面的命令在GCC 4.7.2中出错:
auto f() -> void noexcept {}
// error: expected initializer before ‘noexcept’
我读过的文章没有说过不能在训练返回类型中指定noexcept
。这是一个bug吗(在最新版本的GCC中已经修复了吗)?或者这是标准明确禁止的吗?
语法不正确。应该是:
auto f() noexcept -> void { }
c++ 11标准第8.4.1/2段:
D1
(参数声明子句)cv-qualifier-seq(opt)ref-qualifier(opt) *exception-specification(opt)* attribute-specifier-seq(opt) *trailing-return-type(opt)*
如8.3.5所述。函数只能在命名空间或类作用域中定义。
相关文章:
- 如何获取std::result_of函数的返回类型
- 奇怪的结构&GCC&clang(void*返回类型)
- 如何建立使用模板函数的lambda函数的尾部返回类型
- 为什么与常规GCC不同,即使有"学究性错误",MinGW-GCC也能容忍丢失的返回类型
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- 特征::矩阵<双精度,1,3> 结构类型函数中的返回类型函数
- 函数作为模板参数,是否对返回类型强制约束
- C++中函数的向量返回类型引发错误
- 检查函数返回类型是否与STL容器类型值相同
- 为什么返回类型中需要typename?C++
- <Windows>为什么 std::thread::native_handle 返回类型为"long long unsigned int"的值,而不是 void*(又名 HANDLE)?
- 警告:在函数返回类型 [-Wignore 限定符] 时忽略类型限定符
- 截至 C++14 起尾随返回类型语法的合法使用
- 返回类型布尔函数中的声明语法错误
- 是否可以在尾随返回类型语法中直接使用参数值(不是其类型,而是值本身)
- 嵌套模板类返回类型在 C++ 中的头文件中函数返回类型的语法
- GCC 中的编译器错误,但在将 decltype 与具有尾随返回类型语法的模板化成员函数一起使用时没有 clang
- 是否可以通过从lambda的引用中返回T型对象,而无需使用尾随返回类型语法
- 在后面的返回类型函数语法中,auto关键字背后是否有意图
- 由于noexcept说明符,尾随返回类型语法失败