[cfe-commits] r51772 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/Type.h lib/AST/StmtIterator.cpp

Ted Kremenek kremenek at apple.com
Fri May 30 11:25:15 PDT 2008


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.

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

>
>
>> +  void setInit(Expr *I) { Init = (Stmt*) I; }
>
> Unneeded cast.  Same thing everywhere else.

Not true.  Decl.h does not include Expr.h, so at this point the  
compiler is not guaranteed to know that Expr subclasses Stmt.  Remove  
the cast and you will see that clang doesn't compile.



More information about the cfe-commits mailing list