P1359R0 [basic.lval] 措辞变化和别名规则

P1359R0 [basic.lval] wording change and aliasing rules

C++ 标准的 N4778 草案 (2018) 包含以下部分:

7.2.1 [basic.lval]

If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined:

  • the dynamic type of the object,
  • a cv-qualified version of the dynamic type of the object,
  • a type similar (as defined in 7.5) to the dynamic type of the object,
  • a type that is the signed or unsigned type corresponding to the dynamic type of the object,
  • a type that is the signed or unsigned type corresponding to a cv-qualified version of the dynamic typeof the object,
  • an aggregate or union type that includes one of the aforementioned types among its elements or non-static data members (including, recursively, an element or non-static data member of a subaggregate or contained union),
  • a type that is a (possibly cv-qualified) base class type of the dynamic type of the object,
  • a char, unsigned char, or std::byte type.

然而,draft at eel.is/c++draft/ lists只有3颗子弹(我突出了常见的):

If a program attempts to access the stored value of an object through a glvalue whose type is not similar ([conv.qual]) to one of the following types the behavior is undefined:

  • the dynamic type of the object,
  • a type that is the signed or unsigned type corresponding to the dynamic type of the object,
  • a char, unsigned char, or std​::​byte type.

P1359R0 解释变化:

The aliasing rules of [basic.lval] were adapted from C with additions for C++. However, a number of the points either do not apply or are subsumed by other points. For example, the provision for aggregate and union types is needed in C for struct assignment, which in C++ is done via constructors and assignment operators in C++, not by accessing the complete object. ... It has been suggested that the aliasing rules should be extended to permit an object of an enumeration with a fixed underlying type to alias an object with that underlying type.

能否通俗地解释一下这种措辞变化的实际后果?据我了解,建议 enum class E : T { ... }; 允许别名 T。这个对吗?除了这个还有什么会变成defined/undefined吗?

没有实际后果。

这是一项内务清理,旨在删除 redundant/unused 从 C(或旧版 C++ 标准)继承的规则。它不太符合 "editorial" 的标准,因为它不仅仅是修补 grammar/spelling/formatting,但它也不是语义更改。

您提到的 enum 相关更改并未发生;这只是一个建议,在问题描述中的 "additional note" 中提到。我们可以看到这种情况在未来发生。我个人认为这是个好主意。