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

问题描述

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

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

并且读取一个无效的指针值具有实现的程序结构和正确的数据, (参见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]):

(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 changed the semantics concerning invalid pointer values:

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

将这个从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 ++实现中的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 04:22