================
@@ -457,6 +457,46 @@ void foo() {
 }
 ```
 
+(cplusplus-destroyedaswrongtype)=
+
+#### cplusplus.DestroyedAsWrongType (C++)
+
+Check for storage that is reused by placement new for an object of a different
+type and is then destroyed or deleted as the original type
+([basic.life]/11, [expr.delete]/3). Destructor calls and deletions inside the
+standard library, such as `std::destroy_at`, are reported at the call site.
+
+Deleting or destroying the object through a base class with a virtual
+destructor is allowed. Placement new into raw storage, such as a character
+buffer or memory from `::operator new`, into a union and into an object with a
+trivial destructor is not reported. Members and array elements destroyed by a
+destructor that is not inlined are checked when that destructor is called.
+
+```cpp
+class A {};
+class B {
+public:
+  ~B();
+};
+
+void test1() {
+  B b;
+  new (&b) A;
+} // warn: destructor of 'B' is called on storage that holds an object of
+  //       type 'A'
----------------
NagyDonat wrote:

```suggestion
} // warn: destructor of 'B' is called on an object of type 'A'
```
Minor nit – I think this is also clear enough, and fits in a single line.

https://github.com/llvm/llvm-project/pull/237801
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to