“无效指针值”的文档在C ++实现中的转换 [英] Documentation of "invalid pointer value" conversion in C++ implementations

查看:117
本文介绍了“无效指针值”的文档在C ++实现中的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据C ++标准,每个实现都必须记录实现定义的行为:

According to the C++ Standard, it is mandatory for every implementation to document "implementation-defined behavior":


code> [defns.impl.defined] 实施定义的行为

并且读取一个无效的指针值具有实现的程序结构和正确的数据, (参见4.1 Lvalue-to-Rvalue转换 [conv.lval] ):

And reading an invalid pointer value has implementation-defined behavior (see 4.1 Lvalue-to-rvalue conversion [conv.lval]):


如果glvalue所指向的对象包含无效的指针值(3.7.4.2,3.7.4.3),则该行为是实现定义的。

if the object to which the glvalue refers contains an invalid pointer value (3.7.4.2, 3.7.4.3), the behavior is implementation-defined.

(from draft n4527,but verbiage thatIndirection through an invalid pointer value and passing a invalid pointer value to a deallocation function have undefined behavior。任何其他使用无效指针值都有实现定义的行为。 已经在3.7.4.2中的Deallocation函数 [basic.stc.dynamic.deallocation] 因为至少是草案n3485)

(quote from draft n4527, but verbiage that "Indirection through an invalid pointer value and passing an invalid pointer value to a deallocation function have undefined behavior. Any other use of an invalid pointer value has implementation-defined behavior." has been in 3.7.4.2 Deallocation functions [basic.stc.dynamic.deallocation] since at least draft n3485)

然而,许多流行的实现并没有定义这种行为,许多专家将其描述为未定义的行为。

However, many popular implementations do not define this behavior, and many experts describe this as "undefined behavior" instead.

一个可能导致省略明确的文档的原因是: ,根据我可以确定,无效指针值的评估从附录后面的标准草案中出现的实施定义的行为的索引中缺失。

A likely cause for omission of clear documentation is that, as far as I can determine, evaluation of "invalid pointer values" is missing from the "Index of implementation-defined behavior" which appears in Standard drafts following the appendices.

这是标准中的一个缺陷,自从C ++ 14以来,是否有任何开放的缺陷报告或委员会操作?

Is this a defect in the Standard, and are there any open Defect Reports or committee actions taken since C++14 concerning it?

推荐答案

CWG#1438 更改了有关无效指针值的语义:

CWG #1438 changed the semantics concerning invalid pointer values:


当前的标准说,任何使用无效指针值
会产生未定义的行为(3.7.4.2 [basic.stc。 dynamic.deallocation]
第4段)。这不仅包括解引用指针,而且包括
,甚至只是获取它的值。这种严重的
限制的原因是,过去的一些架构使用专用的
地址寄存器用于指针加载和存储,并且如果例如指针中的段号是目前不是
映射。

目前使用或合理预见的
架构是否需要这些限制尚不清楚。这应该是
调查,看看是否可以放宽限制,只应用
来解除引用指针。

The current Standard says that any use of an invalid pointer value produces undefined behavior (3.7.4.2 [basic.stc.dynamic.deallocation] paragraph 4). This includes not only dereferencing the pointer but even just fetching its value. The reason for this draconian restriction is that some architectures in the past used dedicated address registers for pointer loads and stores and they could fault if, for example, a segment number in a pointer was not currently mapped.

It is not clear whether such restrictions are necessary with architectures currently in use or reasonably foreseen. This should be investigated to see if the restriction can be loosened to apply only to dereferencing the pointer.

[conv.lval]中的更改是 CWG#616 ,它基本上采用了上述方法。

将这个从UB提交到实现定义的行为是有意的,所以我认为在索引中没有这一段是一个疏忽。

The change in [conv.lval] is the resolution of CWG #616, which essentially adopted the above.
Lifting this from UB to implementation-defined behavior was intentional, so I presume the absence of this paragraph in the Index is an oversight.

这篇关于“无效指针值”的文档在C ++实现中的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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