C++ 标准中的哪一段验证了以下示例中使用的表达式“sizeof(S::m + 42)”?
Which paragraph in the C++ Standard validates the expression `sizeof(S::m + 42)`used in the example below?
这是[expr.prim.id]/2 (2.3)中的例子:
struct S {
int m;
};
int i = sizeof(S::m); // OK
int j = sizeof(S::m + 42); // OK
我想知道标准 (N4713) 中的哪一段验证了上面使用的表达式 sizeof(S::m + 42)
。
正如@M.M指出的,sizeof
的操作数可以是任何表达式(8.5.2.3.1):
[...] The operand is either an expression, which is an unevaluated operand, or a parenthesized type-id.
8.5.2.3 中还有一些其他限制,但none适用于此处。
请注意,它提到它可以是一个 未计算的操作数 -- 这使得使用 non-static class 成员 S::m
成为可能在这里,请参阅 (8.2.3.1):
An unevaluated operand is not evaluated. [ Note: In an unevaluated operand, a non-static class member may be named ([expr.prim]) and naming of objects or functions does not, by itself, require that a definition be provided ([basic.def.odr]). An unevaluated operand is considered a full-expression. — end note ]
其中提到了您在问题 (8.4.4.2.3) 中提到的段落:
An id-expression that denotes a non-static data member or non-static member function of a class can only be used: [...] if that id-expression denotes a non-static data member and it appears in an unevaluated operand.
这是[expr.prim.id]/2 (2.3)中的例子:
struct S {
int m;
};
int i = sizeof(S::m); // OK
int j = sizeof(S::m + 42); // OK
我想知道标准 (N4713) 中的哪一段验证了上面使用的表达式 sizeof(S::m + 42)
。
正如@M.M指出的,sizeof
的操作数可以是任何表达式(8.5.2.3.1):
[...] The operand is either an expression, which is an unevaluated operand, or a parenthesized type-id.
8.5.2.3 中还有一些其他限制,但none适用于此处。
请注意,它提到它可以是一个 未计算的操作数 -- 这使得使用 non-static class 成员 S::m
成为可能在这里,请参阅 (8.2.3.1):
An unevaluated operand is not evaluated. [ Note: In an unevaluated operand, a non-static class member may be named ([expr.prim]) and naming of objects or functions does not, by itself, require that a definition be provided ([basic.def.odr]). An unevaluated operand is considered a full-expression. — end note ]
其中提到了您在问题 (8.4.4.2.3) 中提到的段落:
An id-expression that denotes a non-static data member or non-static member function of a class can only be used: [...] if that id-expression denotes a non-static data member and it appears in an unevaluated operand.