[cfe-dev] Who owns declarations?

Douglas Gregor dgregor at apple.com
Mon Dec 22 10:44:59 PST 2008


On Dec 22, 2008, at 7:38 PM, Sebastian Redl wrote:

> Douglas Gregor wrote:
>> I suggest that the CXXCatchStmt own the VarDecl, and be responsible  
>> for its destruction and serialization. This is how  
>> CXXConditionalDeclExpr handles its VarDecl for declarations of  
>> variables within the condition of an "if".
> OK, thanks.
>
> By the way, why does CXXConditionalDeclExpr derive from DeclRefExpr?

I believe it's because IfStmt's condition is an Expr*, so  
CXXConditionalDeclExpr is an Expr that also declares a variable. The  
derivation from DeclRefExpr allows the rest of semantic analysis (that  
knows how to treat a DeclRefExpr as a boolean expression) to deal with  
the declaration.

> That's counter-intuitive from several viewpoints.


How so?

	- Doug



More information about the cfe-dev mailing list