diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2008-01-04 00:27:46 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2008-01-04 00:27:46 +0000 |
commit | 775d5d02af519f871a2bcc48c4aa529cc8f4e94e (patch) | |
tree | d9d4b0a9cdbb5861f05f50c08b94a95e3e2a07ec /clang/Sema/SemaStmt.cpp | |
parent | 816dea2fc5e402dacb86a2e2879d2ac8ac4acffd (diff) | |
download | bcm5719-llvm-775d5d02af519f871a2bcc48c4aa529cc8f4e94e.tar.gz bcm5719-llvm-775d5d02af519f871a2bcc48c4aa529cc8f4e94e.zip |
Patch to add semantics check for ObjC2's foreacn statement.
llvm-svn: 45561
Diffstat (limited to 'clang/Sema/SemaStmt.cpp')
-rw-r--r-- | clang/Sema/SemaStmt.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/clang/Sema/SemaStmt.cpp b/clang/Sema/SemaStmt.cpp index 2c2dc5e3f0c..6b60bd02744 100644 --- a/clang/Sema/SemaStmt.cpp +++ b/clang/Sema/SemaStmt.cpp @@ -538,8 +538,9 @@ Sema::ActOnObjcForCollectionStmt(SourceLocation ForColLoc, Stmt *First = static_cast<Stmt*>(first); Expr *Second = static_cast<Expr*>(second); Stmt *Body = static_cast<Stmt*>(body); - + QualType FirstType; if (DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) { + FirstType = dyn_cast<ValueDecl>(DS->getDecl())->getType(); // C99 6.8.5p3: The declaration part of a 'for' statement shall only declare // identifiers for objects having storage class 'auto' or 'register'. for (ScopedDecl *D = DS->getDecl(); D; D = D->getNextDeclarator()) { @@ -547,19 +548,21 @@ Sema::ActOnObjcForCollectionStmt(SourceLocation ForColLoc, if (BVD && !BVD->hasLocalStorage()) BVD = 0; if (BVD == 0) - Diag(dyn_cast<ScopedDecl>(D)->getLocation(), - diag::err_non_variable_decl_in_for); - // FIXME: mark decl erroneous! + return Diag(dyn_cast<ScopedDecl>(D)->getLocation(), + diag::err_non_variable_decl_in_for); } } + else + FirstType = static_cast<Expr*>(first)->getType(); + if (!isObjcObjectPointerType(FirstType)) + Diag(ForColLoc, diag::err_selector_element_type, + FirstType.getAsString(), First->getSourceRange()); if (Second) { DefaultFunctionArrayConversion(Second); QualType SecondType = Second->getType(); -#if 0 - if (!SecondType->isScalarType()) // C99 6.8.5p2 - return Diag(ForColLoc, diag::err_typecheck_statement_requires_scalar, - SecondType.getAsString(), Second->getSourceRange()); -#endif + if (!isObjcObjectPointerType(SecondType)) + Diag(ForColLoc, diag::err_collection_expr_type, + SecondType.getAsString(), Second->getSourceRange()); } return new ObjcForCollectionStmt(First, Second, Body, ForColLoc); } |