Bee*_*ope 4 c++ memcpy object-lifetime language-lawyer c++17
据我所知,memcpy进入未初始化的存储不能安全地用于创建源对象的副本。
但是,在去年 open-std WG21“ub”列表上的这个线程中,参与者提到了新的 memcpy 生命周期启动规则:
这似乎没有上升到错误报告的级别,但它可能与新的 memcpy 生命周期启动规则有关。他们会为源字节和目标字节分配一些静态类型吗?
Based on the context of the question and small amount of type-erasure example code, it appears that it may be related to creating new objects in aligned_storage via memcpy.
Search as I might, I can't find a reference to the new rules. I'm particularly curious if they only apply to replacing the contents of an already created object, or if they change the situation around the potential creation of an object in uninitialized memory.
The wording has changed a bit, but the general idea remains the same. From intro.object:
An object is created by a definition, by a new-expression, when implicitly changing the active member of a union, or when a temporary object is created ([conv.rval], [class.temporary]).
这些是在 C++ 中创建对象的仅有的四种方法。memcpy不属于这四个条件中的任何一个,因此它现在(以前从未)创建生命周期(隐式更改联合的活动成员可以通过=only完成,而不是 via memcpy)。
引用指的是标准的假设性未来变化,memcpy在某些情况下会祝福这种能力。今年早些时候也有一个关于这个主题的很长的线索。
| 归档时间: |
|
| 查看次数: |
298 次 |
| 最近记录: |