[cfe-commits] r51772 - in /cfe/trunk: include/clang/AST/Decl.h	include/clang/AST/Type.h lib/AST/StmtIterator.cpp
    Eli Friedman 
    eli.friedman at gmail.com
       
    Fri May 30 11:52:16 PDT 2008
    
    
  
On Fri, May 30, 2008 at 11:25 AM, Ted Kremenek <kremenek at apple.com> wrote:
>
> On May 30, 2008, at 10:01 AM, Eli Friedman wrote:
>
>>> Fix some strict-aliasing warnings by using Stmt* instead of Expr* in
>>> VariableArrayType, EnumConstantDecl, and VarDecl.
>>
>> Is it really necessary for StmtIterator to return a "Stmt*&"?  Having
>> an API like that is just asking for trouble.
>
> Originally it just returned Stmt*, but having Stmt*& proved to be extremely
> useful for the Objective-C rewriter.  I agree that it can be a source of
> problems if a client is not careful.
Mmm, not sure what to say.
>>> -  const Expr *getInit() const { return Init; }
>>> -  Expr *getInit() { return Init; }
>>> -  void setInit(Expr *I) { Init = I; }
>>> +  const Expr *getInit() const { return (const Expr*) Init; }
>>> +  Expr *getInit() { return (Expr*) Init; }
>>
>> cast<Expr*>(Init).  Same thing everywhere else.
>
> Using cast<Expr*> requires Decl.h including Expr.h (which is problematic to
> do since Expr.h includes Decl.h).  Use cast<Expr> and you will see that
> clang doesn't compile.  Same argument in Type.h
Oh; oops.  Didn't realize there was a dependency circle there.  I was
hoping we could use the cast templates to catch any mistakes with the
iterators.
-Eli
    
    
More information about the cfe-commits
mailing list