尾随返回类型不是类的完整类上下文是否有特定原因? [英] Is there a specific reason why a trailing-return-type is not a complete-class context of a class?
问题描述
请注意,
一个类的完整类上下文是
A complete-class context of a class is a (6.1)函数主体, (6.1) function body, 在类的成员规范内. [注意:完整的课程
嵌套类的上下文也是任何内容的完整类上下文
封闭类(如果嵌套类是在
封闭类的成员规范. —尾注] within the member-specification of the class. [ Note: A complete-class
context of a nested class is also a complete-class context of any
enclosing class, if the nested class is defined within the
member-specification of the enclosing class. — end note ] [expr.prim.this] p2 也有一个关于此的注意事项: [expr.prim.this]p2 also has a note about this: 如果声明声明一个成员函数或成员函数
X类的模板,它是类型的prvalue的表达式
可选cv-qualifier-seq之间的指向cv-qualifier-seq X的指针"
以及函数定义,成员声明器或函数的末尾
声明者.它不应出现在可选的cv-qualifier-seq之前
并且它不应出现在静态成员的声明中
函数(尽管其类型和值类别是在
静态成员函数,因为它们在非静态成员中
功能). [注意:这是因为声明匹配没有发生
直到知道完整的声明符为止. —尾注] [注:在
尾随返回类型,不需要定义所定义的类
完成以供类成员访问.班级成员宣布
以后将不可见. [示例:... 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, member-declarator, or
declarator. It shall not appear before the optional cv-qualifier-seq
and it shall not appear within the declaration of a static member
function (although its type and value category are defined within a
static member function as they are within a non-static member
function). [ Note: This is because declaration matching does not occur
until the complete declarator is known. — end note ] [ Note: In a
trailing-return-type, the class being defined is not required to be
complete for purposes of class member access. Class members declared
later are not visible. [ Example: ...
因为您不想要它. 现在,您需要各种规则来说明上面的哪些是允许的,哪些是不允许的. Now you need all sorts of rules explaining which of the above is allowed and which is not. 那为什么标准将 noexcept-specifier 放在完整类上下文中?它不会在代码中允许基本上相同的东西吗? So why does the standard places noexcept-specifier in complete-class context? Wouldn't it allow essentially the same thing in code like this: ? 似乎该标准不能很好地解决这个问题,并且编译器对此的处理方式也有所不同. Clang抱怨上面的代码,但是吃了这个: It seems the standard doesn't address this well, and the compilers differ in treatment of this. Clang complains about the above code, but eats this: GCC也抱怨第二个代码,但是接受交换了成员声明的代码.似乎根本没有将noexcept指定符视为完整类上下文. GCC complains about the second code too, but accepts code with the member declarations swapped. It seems it doesn't treat the noexcept specifier as complete-class context at all. 这篇关于尾随返回类型不是类的完整类上下文是否有特定原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
(6.2)默认参数,
(6.3)noexcept-specifier([except.spec]),
(6.4)合同条件,或
(6.5)默认成员初始化器
(6.2) default argument,
(6.3) noexcept-specifier ([except.spec]),
(6.4) contract condition, or
(6.5) default member initializer
推荐答案
struct Test {
auto foo() -> decltype(bar());
auto bar() -> int;
auto baz() -> decltype(qux());
auto qux() -> decltype(baz());
};
struct Test {
void foo() noexcept(noexcept(bar()));
void bar() noexcept(noexcept(foo()));
};
struct Test {
void foo() noexcept(Test::b);
static const bool b = true;
};