[cfe-commits] r41934 - in /cfe/trunk: AST/Decl.cpp CodeGen/CGExpr.cpp CodeGen/CodeGenModule.cpp CodeGen/CodeGenModule.h Driver/ASTStreamers.cpp Sema/Sema.h Sema/SemaDecl.cpp Sema/SemaStmt.cpp include/clang/AST/Decl.h include/clang/AST/Expr.h include/clang/AST/Stmt.h
Chris Lattner
clattner at apple.com
Sun Sep 30 00:59:25 PDT 2007
On Sep 13, 2007, at 2:41 PM, Steve Naroff wrote:
> Author: snaroff
> Move Identifier/Loc instance variables (and associated getters/
> setters) down from Decl to ScopedDecl/FieldDecl.
> Objc AST's can now inherit from Decl without getting instance
> variables and types that are C specific. For now, I am keeping
> NextDeclarator, since I believe it may be useful to ObjC. If not,
> it can be moved later.
Nice! Some more cast vs dyn_cast stuff:
> ======================================================================
> ========
> --- cfe/trunk/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/Sema/SemaDecl.cpp Thu Sep 13 16:41:19 2007
> @@ -571,7 +571,8 @@
>
> VarDecl *VDecl = dyn_cast<VarDecl>(RealDecl);
> if (!VDecl) {
> - Diag(RealDecl->getLocation(), diag::err_illegal_initializer);
> + Diag(dyn_cast<ScopedDecl>(RealDecl)->getLocation(),
> + diag::err_illegal_initializer);
> RealDecl->setInvalidDecl();
> return;
> }
This code should use cast<> instead of dyn_cast<> because it
unconditionally dereferences the pointer returned.
> ======================================================================
> ========
> --- cfe/trunk/Sema/SemaStmt.cpp (original)
> +++ cfe/trunk/Sema/SemaStmt.cpp Thu Sep 13 16:41:19 2007
> @@ -33,9 +33,11 @@
> }
>
> Sema::StmtResult Sema::ParseDeclStmt(DeclTy *decl) {
> + if (decl) {
> + ScopedDecl *SD = dyn_cast<ScopedDecl>(static_cast<Decl *>(decl));
> + assert(SD && "Sema::ParseDeclStmt(): expected ScopedDecl");
Likewise: if you replace the dyncast with a cast, you can drop the
assert...
> @@ -57,7 +59,7 @@
> /*empty*/;
>
> if (i != NumElts) {
> - Decl *D = cast<DeclStmt>(Elts[i])->getDecl();
> + ScopedDecl *D = cast<DeclStmt>(Elts[i])->getDecl();
> Diag(D->getLocation(), diag::ext_mixed_decls_code);
... Which would be consistent with this one :)
> @@ -484,7 +486,8 @@
> if (BVD && !BVD->hasLocalStorage())
> BVD = 0;
> if (BVD == 0)
> - Diag(D->getLocation(), diag::err_non_variable_decl_in_for);
> + Diag(dyn_cast<ScopedDecl>(D)->getLocation(),
> + diag::err_non_variable_decl_in_for);
This should be cast.
-Chris
More information about the cfe-commits
mailing list