Is `this` allowed inside a noexcept specification?

前端 未结 1 1217
渐次进展
渐次进展 2021-01-17 23:14

I have some code which requires me to use *this, but I want it to be noexcept friendly:

struct foo;

// Would actually be something with conditi         


        
相关标签:
1条回答
  • 2021-01-17 23:57

    Yes, it is allowed. [expr.prim.this]p2 says:

    If a declaration declares a member function or member function template of a class X, the expression this is a prvalue of type “pointer to cv-qualifier-seq X” between the optional cv-qualifier-seq and the end of the function-definition, [...].

    The cv-qualifier-seq refers to the cv qualifiers of the member function, which appear before the noexcept specifier:

    parameters-and-qualifiers:
        ( parameter-declaration-clause ) cv-qualifier-seq[opt] ref-qualifier[opt] 
          noexcept-specifier[opt] attribute-specifier-seq[opt]
    

    So, this is a valid expression to use in the noexcept-specifier. This was a DR (cwg1207), which gcc doesn't implement. The bug report.

    0 讨论(0)
提交回复
热议问题