我只是听不懂DR 712 [英] I just can not understand DR 712

查看:110
本文介绍了我只是听不懂DR 712的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DR 712 负责将C ++ 11中[basic.def.odr]/2的措辞更改为今天的当前措辞,即

DR 712 was responsible for the change in the wording of [basic.def.odr]/2 in C++11 to the current wording today, in [basic.def.odr]2 and 3. But I'm still trying to understand the reason for the change, as stated in the DR, as follows:

712.条件表达式的整数常量操作数是否被使用"?

在描述类内部初始化的静态数据成员时 定义,9.2.3.2 [class.static.data]第3段说,

In describing static data members initialized inside the class definition, 9.2.3.2 [class.static.data] paragraph 3 says,

如果使用该成员,则仍应在名称空间范围内对其进行定义 在程序中...

The member shall still be defined in a namespace scope if it is used in the program...

3.2 [basic.def.odr]第1段中已使用"的定义:

The definition of "used" is in 3.2 [basic.def.odr] paragraph 1:

   对象或非重载函数,其 名称显示为可能被评估的
   ""除非它是满足出现在广告代码中的要求的对象,否则将使用该表达式.    常量表达式(5.20 [expr.const])和左值到右值转换(4.1 [conv.lval])
    立即生效.

    An object or non-overloaded function whose name appears as a potentially-evaluated
    expression is used unless it is an object that satisfies the requirements for appearing in a     constant expression (5.20 [expr.const]) and the lvalue-to-rvalue conversion (4.1 [conv.lval])
    is immediately applied.

现在考虑以下示例:

 struct S {
      static const int a = 1;
      static const int b = 2;
 };
 int f(bool x) {
      return x ? S::a : S::b;
 }

根据本标准的当前措辞,此示例 要求在名称空间范围内定义S::aS::b.这 原因是,根据5.16 [expr.cond]第4段, 此条件表达式的结果是一个左值,而 左值到右值的转换将应用于此值,而不是直接应用于 对象,因此不符合立即应用"的要求.这是 令人惊讶和不幸的是,因为只有价值观而不是 使用静态数据成员的地址. (这个问题也 适用于第696期建议的决议.)

According to the current wording of the Standard, this example requires that S::a and S::b be defined in a namespace scope. The reason for this is that, according to 5.16 [expr.cond] paragraph 4, the result of this conditional-expression is an lvalue and the lvalue-to-rvalue conversion is applied to that, not directly to the object, so this fails the "immediately applied" requirement. This is surprising and unfortunate, since only the values and not the addresses of the static data members are used. (This problem also applies to the proposed resolution of issue 696.)

好吧,如果立即应用的需求失败,那么条件表达式中的表达式S::aS::b不会被使用(strong>已使用),因此将分别使用静态成员struct S不需要不需要在命名空间范围内定义.但这与DR所说的完全相反.我缺少什么??

Well, if the "immediately applied requirement fails, then the expressions S::a and S::b in the conditional expression are not used (odr-used), and so, the respective static members of struct S will not need to be defined in namespace scope. But this is exactly the opposite of what the DR is saying. What am I missing???

推荐答案

我认为您缺少used定义的要点:

I think you're missing the point of the used definition:

it is used UNLESS ( (const) AND (immediately applied) )

因此,如果立即应用"为假,则UNLESS为假,因此将其使用.

So, if "immediately applied" is false, then the UNLESS is false, and thus it is used.

这篇关于我只是听不懂DR 712的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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