☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

将对象的值赋给具有部分重叠区域的另一个对象

C++-Undefined-Behavior-49
目录 › next › previous

示例:

int a[3] {1, 2, 3};

struct A {
    int x, y;
};

A* p = reinterpret_cast<A*>(a);
A* q = reinterpret_cast<A*>(a + 1);

*p = *q;   // Undefined behavior

例中 p 和 q 指向的对象具有部分重叠的区域,*p = *q 或 *q = *p 均会导致未定义的行为。

依据

ISO/IEC 14882:2003 5.17(8)-undefined ISO/IEC 14882:2011 5.17(8)-undefined

规则

ID_overlappingAssignment
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.