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

对象的实际类型与当前静态类型不相关,并调用其析构函数

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

示例:

struct T { .... };
struct U { .... };

void foo(void* p) {
    delete static_cast<T*>(p);   // Undefined behavior
}

void bar() {
    foo(new U);
}

例中 p 实际指向的不是 T 类型的对象,程序的行为是未定义的。

依据

ISO/IEC 14882:2003 12.4(12)-undefined ISO/IEC 14882:2011 12.4(13)-undefined

规则

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