noexcept depend on noexcept of a member function

前端 未结 1 958
终归单人心
终归单人心 2021-01-05 02:26

Consider:

class test {
    private:
        int n;

        int impl () const noexcept {
            return n;
        }

    public:
        test () = delet         


        
相关标签:
1条回答
  • 2021-01-05 03:10

    The rules for where this can be used changed as a result of core language issue 1207, actually for another reason but in a way that also affects noexcept expressions.

    Before (after C++03, but when C++11 was still being written), this was not allowed to be used outside a function body. The noexcept expression is not part of the body, so this could not be used.

    After, this can be used anywhere after the cv-qualifier-seq, and noexcept expressions appear after that, as the code in your question clearly illustrates.

    It looks like the GCC implementation of this issue is incomplete, and only allows member functions in trailing function return types, but the standard has opened up more than that. I recommend reporting this as a bug (if it has not previously been reported). This has already been reported on GCC bugzilla as bug 52869.

    For whatever it's worth, clang accepts the code in C++11 mode.

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