NoQ added a comment.

Thanks! This looks very useful.

Comment at: clang/lib/Analysis/CallGraph.cpp:97-102
+    const auto *ConstructedType = Ctor->getParent();
+    if (ConstructedType->hasUserDeclaredDestructor()) {
+      CXXDestructorDecl *Dtor = ConstructedType->getDestructor();
+      if (FunctionDecl *Def = Dtor->getDefinition())
+        addCalledDecl(Def);
+    }
Ugh this is questionable. The object may easily outlive the function, so the 
destructor may be called from another function. I see where this was supposed 
to go (i.e., this is perfectly correct when the constructor is constructing a 
non-RVO'd temporary or a non-NRVO'd local variable), but in the general case 
it's not true.

The really nice way to implement this functionality would be to rely on the 
constructor's `ConstructionContext`, but as of now it's only available in the 
CFG and there's no easy way to retrieve it by looking at the AST node (and if 
you have a CFG you might as well look at destructors directly, as they're 
listed there explicitly).

It should also be possible to do that by hand by matching `DeclStmt`s and 

Let's omit this part for now because currently the analysis seems to be 
conservative in the sense that it doesn't add calls when it's not sure.


cfe-commits mailing list

Reply via email to