What does Note 10 mean in [basic.lval]/11?

Viewed 111

[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]

1 Answers

This note is language lawyering at its best!

While defining its equivalent rule (§6.5/7 in C99), C bundles in aggregates and union types when describing the valid aliasing possibilities.

C++ doesn't do that. With constructors, conversion operators and inheritance thrown into the mix, classes can be lot more complex than any compound types found in C, so C++ throws up its arms and says, look, we're not going to deal with any of that here.

Instead, "accesses" described by these rules come down to built-in types only. And that's fine, because every compound type is, ultimately, made up of objects of built-in types.

What constitutes valid conversions and reinterpretations of complex types is covered by different rules elsewhere.

This note simply points that out.

The same is described in slightly more detail in the standard's glossary:

[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]

Ultimately, we don't really need to worry about it.

Related