C++ noexcept依赖于成员函数的noexcept

C++ noexcept依赖于成员函数的noexcept,c++,gcc,noexcept,C++,Gcc,Noexcept,考虑: 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()))

考虑:

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:错误:不完整类型“类测试”的使用无效
int get()const noexcept(noexcept(std::declval().impl()){
^
test.cpp:8:7:错误:“类测试”的转发声明
课堂测试{

这是标准规定的预期行为,还是GCC(4.8.0)中的缺陷?

此的使用规则可能会因为其他原因而改变,但也会影响
noexcept
表达式

在此之前(C++03之后,但C++11仍在编写时),
不允许在函数体外部使用。
noexcept
表达式不是函数体的一部分,因此无法使用此

之后,
可以在cv限定符seq之后的任何位置使用,
noexcept
表达式出现在其后,正如您问题中的代码清楚地说明的那样

看起来这个问题的GCC实现是不完整的,只允许在后续函数返回类型中使用成员函数,但该标准已经开放了更多。我建议将其报告为错误(如果以前没有报告过)。这已经在GCC bugzilla上报告为

不管值多少钱,clang都接受C++11模式下的代码

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 {