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

具有静态、线程或自动存储期和 non-trivial 析构函数的对象,其空间被非兼容类型的对象占据

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

示例:

struct A { ~A(); };
struct B { ~B(); };

void foo() {
    A a;
    new (&a) B;
}   // Undefined behavior

例中局部对象 a 的空间被不相关类型的对象占据,在 foo 函数返回前仍会调用 A 的析构函数,导致未定义的行为。

依据

ISO/IEC 14882:2003 3.8(8)-undefined ISO/IEC 14882:2011 3.8(8)-undefined
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.