c++ - 这个 noexcept 声明有效吗?

标签 c++ visual-c++ g++ clang++

struct X
{
    void f() noexcept(noexcept(g()));
    void g() noexcept;
};

在 vc++ 和 clang 中,这可以工作,但 gcc 会提示:

source_file.cpp:6:34: error: ‘g’ was not declared in this scope
     void f() noexcept(noexcept(g()));
                                  ^

我认为这是 gcc 中的一个错误,而不是其他 gcc 中的功能。这是正确的吗?

最佳答案

您的评估是 correct

Within the class member-specification, the class is regarded as complete within function bodies, default arguments, noexcept-specifiers, and default member initializers (including such things in nested classes). Otherwise it is regarded as incomplete within its own class member-specification.

在完整类型的范围内,g 应该由 unqualified name lookup 找到。

关于c++ - 这个 noexcept 声明有效吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55677543/

相关文章:

c++ - 在同一语句中调用的 IO 执行函数 : Undefined or unspecified?

c++ - Windows 中通配符搜索中的问号

c++ - 如何为大多数系统编译 LD_PRELOAD

libraries - 对符号 'BIO_ctrl@@libcrypto.so.10' 的 undefined reference

c++ - CMake 库相邻子目录依赖

c++ - 如何使用 OpenImageIO 和 read_tiles() 读取平铺图像

c++ - QTabWidget 内容不展开

c++ - SFINAE - 尝试确定模板类型是否具有返回类型为 'variable' 的成员函数

c - 为什么结构的大小不等于其各个成员类型的大小之和?

c++ - 忽略 g++ 编译错误以获得向后兼容性的额外资格