[cfe-dev] Parser Stmt/Expr Owning Pointer

Sebastian Redl sebastian.redl at getdesigned.at
Tue Dec 9 11:39:21 PST 2008


Howard Hinnant wrote:
> I haven't traced this down exactly, so I'm not sure there's a  
> problem.  But in:
>
>    template <void (Action::*Destroyer)(void*)>
>    class ASTMove {
>      ASTOwner<Destroyer> &Moved;
>
>    public:
>      explicit ASTMove(ASTOwner<Destroyer> &moved) : Moved(moved) {}
>      ...
>
> we store a reference to the ASTOwner.  And I also see client code that  
> looks like:
>
>      ExprOwner Idx(Actions, ParseAssignmentExpression());
>      if (Idx.isInvalid()) {
>        SkipUntil(tok::r_square);
>        return Idx.move();
>      }
>
> Are we in danger of returning a reference to the local variable Idx?
>   
No. The return type is an ExprResult, which is initialized with the 
ASTMove. As long as no one gets the idea that using an ASTMove as a 
return type is a good thing (it *isn't*), there's no problem.

Sebastian



More information about the cfe-dev mailing list