[cfe-dev] Who owns declarations?

Douglas Gregor dgregor at apple.com
Mon Dec 22 10:29:36 PST 2008


On Dec 22, 2008, at 7:22 PM, Sebastian Redl wrote:
> I'm currently implementing Sema and AST support for C++ try-catch
> statements, and I'm confused about ownership.
>
> A basic C++ try-catch looks like this:
>
> try { ... }
> catch (exception_type exception_var) { ... }
>
> "exception_type exception_var" is a 'exception-declaration'  
> production;
> very much like a function parameter declaration, actually. I use  
> VarDecl
> to represent it in the AST, though.
> However, I'm somewhat confused as to who owns the VarDecl. Should I
> destroy it when the CXXCatchStmt is destroyed? Should I serialize it  
> as
> owned or as unowned?


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".

	- Doug



More information about the cfe-dev mailing list