[cfe-dev] Analyzer - CXXDestructorCall functioning

Artem Dergachev via cfe-dev cfe-dev at lists.llvm.org
Tue Aug 30 04:09:56 PDT 2016


In this case the call event is missing because A is Plain Old Data and 
needs no destructor. Even in -ast-dump, i don't see the destructor 
declaration, so assuming the dump is complete, i guess your 
dyn_cast<CXXDestructorDecl> is bound to fail. If you add, say, "~A(){}" 
to the class definition, the callback starts firing.

However, there might be more bugs in the area of destructors, especially 
when it comes to temporary objects.

The documentation you quoted sounds strange - at least, i expect this 
call event to work for *explicit* destructors.


On 8/30/16 12:06 PM, Péter Szécsi via cfe-dev wrote:
> Hi!
>
> I was implementing a SA checker when I ran into the next (problem?) :
> Whenever I write a callback PostCall/PreCall with the next body:
>
> {
> if (dyn_cast<CXXDestructorCall>(&Call))
>     llvm::errs() << "DtorCall\n";
>
>   if (dyn_cast<CXXDestructorDecl>(Call.getDecl()))
>     llvm::errs() << "DtorDecl\n";
>
>   return;
> }
>
> Then I could not find a case where the cast to CXXDestructorCall is 
> successful.
> Running this simple "checker" on the *below example emitted no output* 
> to errs:
>
> class A {
> };
> int main()
> {
> A a;
>  {
>  A b;
>  }
> }
>
> However if change the inner block this way:
>  {
>  A b;
>  b.~A();
>  }
> then "DtorDecl" is displayed which makes sense.
>
> The detailed description of the CXXDestructorCall says:
>
>     Represents an implicit call to a C++ destructor.
>
>     This *can* occur at the end of a scope (for automatic objects), at
>     the end of a full-expression (for temporaries), or as part of a
>     delete.
>
> My question is: Does "can" mean in this context that the callback is 
> quite unreliable even in trivial cases or is it a bug and the 
> destructor call should trigger?
>
> Thanks,
>
> Peter



More information about the cfe-dev mailing list