gpt4 book ai didi

c++ - 赋值操作标准变更

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:56:57 25 4
gpt4 key购买 nike

有人可以举例说明新标准中以下内容的变化吗?这是指严格的别名规则吗?

5.17/8. If the value being stored in an object is accessed from another object that overlaps in any way the storage of the first object, then the overlap shall be exact and the two objects shall have the same type, otherwise the behavior is undefined.

在新标准中,它被更改为以下注释:

[ Note: This restriction applies to the relationship between the left and right sides of the assignment operation; it is not a statement about how the target of the assignment may be aliased in general. See 3.10. — end note ]

最佳答案

这解释了变化:http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#556

There appear to be two different specifications for when aliasing is permitted.

[...]

This issue is based on a misunderstanding of the intent of the wording in 5.17 [expr.ass] paragraph 8. Instead of being a general statement about aliasing, it's describing the situation in which the source of the value being assigned is storage that overlaps the storage of the target object. The proposed resolution should make that clearer rather than changing the specification.

关于c++ - 赋值操作标准变更,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8423713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com