Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ noexcept规范中是否允许使用“this”?_C++_This_Language Lawyer_Noexcept - Fatal编程技术网

C++ noexcept规范中是否允许使用“this”?

C++ noexcept规范中是否允许使用“this”?,c++,this,language-lawyer,noexcept,C++,This,Language Lawyer,Noexcept,我有一些代码需要我使用*此,但我希望它不会异常友好: struct foo; // Would actually be something with conditional noexcept void do_something(foo&); struct foo { void fn() noexcept(noexcept(::do_something(*this))) { ::do_something(*this); } };

我有一些代码需要我使用
*此
,但我希望它不会异常友好:

struct foo;

// Would actually be something with conditional noexcept
void do_something(foo&);

struct foo {
    void fn()
        noexcept(noexcept(::do_something(*this)))
    {
        ::do_something(*this);
    }
};
然而:

但是,如果我通过
this
指针访问该成员:

诊断:

<source>:7:42: error: invalid use of 'this' at top level
         noexcept(noexcept(::do_something(this->x)))
:7:42:错误:在顶层无效使用“this”
noexcept(noexcept(::dou_something(this->x)))
我试过的所有其他编译器,但我不知道是gcc还是所有其他编译器都有缺陷

关键字
是否可以在noexcept规范中使用?

是的,它是允许的。说:

如果声明声明了类
X
的成员函数或成员函数模板,则表达式
this
是可选cv限定符seq和函数定义末尾[…]之间类型为“指向cv限定符seq
X
”的PR值

cv限定符seq是指成员函数的cv限定符,它:


因此,
这个
是在noexcept说明符中使用的有效表达式。这是一个DR(),gcc没有实现。.

在bug报告中找到了不错的结果。我在gcc bugzilla中搜索了,但没有找到这个。@Justin我搜索了“这个没有例外”:
void do_something(int);

struct bar {
    int x;

    void fn()
        noexcept(noexcept(::do_something(x)))
    {
        ::do_something(x);
    }
};
struct baz {
    int x;

    void fn()
        noexcept(noexcept(::do_something(this->x)))
    {
        ::do_something(this->x);
    }
};
<source>:7:42: error: invalid use of 'this' at top level
         noexcept(noexcept(::do_something(this->x)))
parameters-and-qualifiers:
    ( parameter-declaration-clause ) cv-qualifier-seq[opt] ref-qualifier[opt] 
      noexcept-specifier[opt] attribute-specifier-seq[opt]