否除非依赖于成员函数的否
noexcept depend on noexcept of a member function
考虑:
class test {
private:
int n;
int impl () const noexcept {
return n;
}
public:
test () = delete;
test (int n) noexcept : n(n) { }
int get () const noexcept(noexcept(impl())) {
return impl();
}
};
海湾合作委员会说不:
test.cpp:27:43: error: cannot call member function 'int test::impl() const' with
out object
int get () const noexcept(noexcept(impl())) {
同样地:
test.cpp:27:38: error: invalid use of 'this' at top level
int get () const noexcept(noexcept(this->impl())) {
和
test.cpp:31:58: error: invalid use of incomplete type 'class test'
int get () const noexcept(noexcept(std::declval<test>().impl())) {
^
test.cpp:8:7: error: forward declaration of 'class test'
class test {
这是符合标准的预期行为,还是 GCC (4.8.0) 中的错误?
由于我建议将此报告为错误(如果以前未报告过)。这已经在GCC bugzilla上报告为错误52869。
核心语言问题 1207,this
的使用规则发生了变化,实际上是出于另一个原因,但也会影响noexcept
表达式。
之前(在 C++03 之后,但当 C++11 仍在编写时),不允许在函数体之外使用this
。noexcept
表达式不是身体的一部分,因此无法使用this
。
之后,this
可以在 cv-qualifier-seq 之后的任何地方使用,之后会出现noexcept
表达式,正如您问题中的代码清楚地说明的那样。
看起来这个问题的 GCC 实现不完整,只允许尾随函数返回类型的成员函数,但标准已经开放了更多。
无论它的价值如何,clang 都会以 C++11 模式接受代码。
相关文章:
- 如何使用指针传递给函数的数组中对象的函数成员
- c++构造函数成员初始化:传递参数
- 创建 std::函数,它返回具有函数成员值的变量.分段错误
- 如何在C++通过公共函数访问私有函数成员?
- 解释了构造函数成员初始化列表
- 调用std::函数成员时内存损坏
- 是否可以为模板类的模板函数成员设置别名?
- 捕获 lambda 函数C++成员变量
- 构造函数成员初始值设定项跨成员列出,安全吗?
- 获取与在模板参数中传递的函数成员类型相同的类
- 如何从公共函数成员访问地图私有成员
- C 构造函数成员分配优化
- 使用命名空间进行函数成员定义
- 函数成员作为 CUDA 内核的参数
- 模板基类函数成员的别名
- 函数成员中用于void和继承的enable_if
- 头文件中是否定义了一个很长的Class函数成员
- 类内/构造函数成员初始化
- 使用指向部分专用函数成员的指针自动填充向量
- 指向函数成员的指针