P1359R0 [basic.lval]字词更改和别名规则 [英] P1359R0 [basic.lval] wording change and aliasing rules

查看:53
本文介绍了P1359R0 [basic.lval]字词更改和别名规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The N4778 draft (2018) of the C++ standard contains the following section:

7.2.1 [basic.lval]

7.2.1 [basic.lval]

如果程序尝试通过以下类型之一以外的glvalue访问对象的存储值,则行为未定义:

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:

  • 对象的动态类型
  • 对象的动态类型的cv限定版本,
  • 类似于对象的动态类型的类型(定义见7.5)
  • 一种类型,它是与对象的动态类型相对应的有符号或无符号类型
  • 一种类型,它是与对象的动态类型的cv限定版本相对应的有符号或无符号类型,
  • 在其元素或非静态数据成员(包括递归地包括子聚合或所包含的并集的元素或非静态数据成员)中包括上述类型之一的集合或联合类型,
  • 一种类型,它是对象动态类型的(可能是cv限定的)基类类型,
  • char unsigned char std :: byte 类型.

但是,在eel.is/c++draft/中的草案列出仅3个项目符号(我突出了常见项目符号):

However, the draft at eel.is/c++draft/ lists only 3 bullets (I highlighted the common ones):

如果程序试图通过glvalue访问对象的存储值,该glvalue的类型与以下一种类型不相似([conv.qual]),则行为未定义:

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:

  • 对象的动态类型
  • 一种类型,它是与对象的动态类型相对应的有符号或无符号类型
  • 一种 char unsigned char std :: byte 类型.

P1359R0 解释更改:

[basic.lval]的别名规则是从C改编而来的,为C ++提供了附加功能.但是,许多要点要么不适用,要么被其他要点所包含.例如,在C中需要为集合和联合类型提供结构分配,这在C ++中是通过C ++中的构造函数和赋值运算符完成的,而不是通过访问完整的对象来完成的....已经建议应扩展别名规则,以允许具有固定基础类型的枚举对象对具有该基础类型的对象进行别名.

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.

您能否以通俗易懂的方式解释这种措词更改的实际后果?据我了解,建议枚举类E:T {...}; 允许使用别名 T .这样对吗?除此之外,还会有其他定义/未定义的内容吗?

Could you please explain in layman's terms the practical consequences of this wording change? As far as I understand, enum class E : T { ... }; is suggested to allow to alias T. Is this correct? Will anything else besides this become defined/undefined?

推荐答案

没有实际后果.

这是一次内部清理,以删除从C(或较旧的C ++标准)继承的冗余/未使用规则.它不完全符合编辑"的标准,因为它不仅修饰语法/拼写/格式,而且也不是语义上的改变.

This is a housekeeping clean-up to remove redundant/unused rules inherited from C (or older C++ standards). It doesn't quite meet the criteria of "editorial" because it's not just tinkering with grammar/spelling/formatting, but it's not a semantics change either.

您提到的与 enum 相关的更改没有发生;这只是一个建议,在问题说明中的其他说明"中提到过.我们可以看到这种情况将来会发生.我个人认为这是个好主意.

The enum-related change you mention didn't happen; it's just a suggestion, mentioned in an "additional note" within the issue description. We could see this happen in future. Personally, I think that would be a good idea.

这篇关于P1359R0 [basic.lval]字词更改和别名规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆