[cfe-dev] Who owns declarations?
Sebastian Redl
sebastian.redl at getdesigned.at
Mon Dec 22 11:05:25 PST 2008
Douglas Gregor wrote:
>
> On Dec 22, 2008, at 7:38 PM, Sebastian Redl wrote:
>
>>
>> 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?
>
A CXXConditionalDeclExpr declares a variable, it doesn't reference it.
That's the most important difference between the two, and it doesn't
lend itself to using derivation - note that CXXConditionalDeclExpr
doesn't have serialization implemented, precisely because it owns the
Decl and DeclRefExpr doesn't, which causes confusion.
Sebastian
More information about the cfe-dev
mailing list