llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.76k stars 10.97k forks source link

clang-analyzer-alpha.cplusplus.DeleteWithNonVirtualDtor is bogus #62685

Open tiagomacarios opened 1 year ago

tiagomacarios commented 1 year ago

The following code will trigger clang-analyzer-alpha.cplusplus.DeleteWithNonVirtualDtor https://godbolt.org/z/dxdYe1zc8

struct B{};

struct D : B{};

void fun()
{
    B* b = new D{};
    delete b;
}
Error output ```console :8:5: warning: Destruction of a polymorphic object with no virtual destructor [clang-analyzer-alpha.cplusplus.DeleteWithNonVirtualDtor] delete b; ^~~~~~~~ :7:12: note: Conversion from derived to base happened here B* b = new D{}; ^~~~~~~ :8:5: note: Destruction of a polymorphic object with no virtual destructor delete b; ^~~~~~~~ 1 warning generated. ```

Looking at the code in DeleteWithNonVirtualDtorChecker.cpp it looks like we are missing a check for DerivedClass->isPolymorphic()

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-static-analyzer