[cfe-dev] C++ Constructors & Destructors in the AST

Anders Carlsson andersca at me.com
Sun Apr 26 12:37:34 PDT 2009


26 apr 2009 kl. 04.35 skrev Sebastian Redl:

> So where do CXXTemporaryObjectExpr and CXXExprWithCleanup fit into  
> this
> scheme?

Hi Sebastian!

Sorry for not replying earlier. Here's the current design:

CXXConstructExpr represents a (possibly implicit) call to a  
constructor. For example the declaration

T t;

will have its initializer set to a CXXConstructExpr. (Assuming T is a  
class type with a non-trivial constructor of course)

CXXTemporaryObjectExpr represents a temporary - it inherits from  
CXXConstructExpr since it creates a temporary expr.

T();

will be represented by a CXXTemporaryObjectExpr.


> Especially CXXExprWithCleanup has me stumped. How is it going to be
> used? Where is it inserted into the AST? What does it mean?

A CXXExprWithCleanup represents a full expression that creates  
temporaries that needs to have their destructors called.

For example the example above,

T();

would look something like

(CXXExprWithCleanup
   (CXXTemporaryObjectExpr("temp", "T::T")
   ("temp"))

In the first design that we came up with, we would have explicit  
CXXDestroyExprs that would be inserted after statements, but that  
won't work with things like the for loop condition expr. I plan to  
remove the CXXDestroyExpr node.

Does this sound OK? Maybe we should rename CXXExprWithCleanup to  
CXXExprWithTemporaries? I'll add some documentation shortly.

Anders



More information about the cfe-dev mailing list