[basic.lval]/11 中的注释 10 是什么意思?
What does Note 10 mean in [basic.lval]/11?
If a program attempts to access the stored value of an object through a glvalue whose type is not similar to one of the following types the behavior is undefined:48
(11.1)
the dynamic type of the object,
(11.2)
a type that is the signed or unsigned type corresponding to the dynamic type of the object, or
(11.3)
a char
, unsigned char
, or std::byte
type.
If a program invokes a defaulted copy/move constructor or copy/move assignment operator for a union of type U
with a glvalue argument that does not denote an object of type cv U
within its lifetime, the behavior is undefined.
[Note 10: Unlike in C, C++ has no accesses of class type. — end note]
这篇笔记是最好的语言律师!
在定义其等效规则(C99 中的 §6.5/7)时,C 在描述有效的别名可能性时捆绑在聚合和联合类型中。
C++ 不会那样做。随着构造函数、转换运算符和继承的混合,类 可能比 C 中发现的任何复合类型都复杂得多,所以 C++ 举起手臂说,看,我们不打算处理任何在这里。
相反,这些规则描述的“访问”仅归结为内置类型。这很好,因为每个复合类型最终都是由内置类型的对象组成的。
复杂类型的有效转换和重新解释由其他地方的不同规则涵盖。
这篇笔记只是指出了这一点。
在标准的词汇表中有更详细的描述:
[defns.access]
: [..] [Note 1: Only objects of scalar type can be accessed. Reads of scalar objects are described in [conv.lval] and modifications of scalar objects are describred in [expr.ass], [expr.post.incr], and [expr.pre.incr]. Attempts to read or modify an object of class type typically invoke a constructor or assignment operator; such invocations do not themselves constitute accesses, although they may involve accesses of scalar subobjects. — end note]
最终,我们真的不需要担心它。
If a program attempts to access the stored value of an object through a glvalue whose type is not similar to one of the following types the behavior is undefined:48
(11.1) the dynamic type of the object,
(11.2) a type that is the signed or unsigned type corresponding to the dynamic type of the object, or
(11.3) a
char
,unsigned char
, orstd::byte
type.If a program invokes a defaulted copy/move constructor or copy/move assignment operator for a union of type
U
with a glvalue argument that does not denote an object of typecv U
within its lifetime, the behavior is undefined.[Note 10: Unlike in C, C++ has no accesses of class type. — end note]
这篇笔记是最好的语言律师!
在定义其等效规则(C99 中的 §6.5/7)时,C 在描述有效的别名可能性时捆绑在聚合和联合类型中。
C++ 不会那样做。随着构造函数、转换运算符和继承的混合,类 可能比 C 中发现的任何复合类型都复杂得多,所以 C++ 举起手臂说,看,我们不打算处理任何在这里。
相反,这些规则描述的“访问”仅归结为内置类型。这很好,因为每个复合类型最终都是由内置类型的对象组成的。
复杂类型的有效转换和重新解释由其他地方的不同规则涵盖。
这篇笔记只是指出了这一点。
在标准的词汇表中有更详细的描述:
[defns.access]
: [..] [Note 1: Only objects of scalar type can be accessed. Reads of scalar objects are described in [conv.lval] and modifications of scalar objects are describred in [expr.ass], [expr.post.incr], and [expr.pre.incr]. Attempts to read or modify an object of class type typically invoke a constructor or assignment operator; such invocations do not themselves constitute accesses, although they may involve accesses of scalar subobjects. — end note]
最终,我们真的不需要担心它。