]> granicus.if.org Git - clang/commitdiff
Don't issue spurious diagnostic with Obj-C fast enumeration.
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 19 Nov 2009 22:12:37 +0000 (22:12 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 19 Nov 2009 22:12:37 +0000 (22:12 +0000)
(radar 7409165).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89400 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Parse/Action.h
lib/Parse/ParseStmt.cpp
lib/Sema/Sema.h
lib/Sema/SemaStmt.cpp
test/SemaObjC/foreach.m

index 3d3232b6f68ea3bf428b841b618daf5425c6cf26..45891bc0c9807e8c39f05309e766fac0fc325704 100644 (file)
@@ -668,6 +668,9 @@ public:
     return StmtEmpty();
   }
 
+  virtual void ActOnForEachDeclStmt(DeclGroupPtrTy Decl) {
+  }
+
   virtual OwningStmtResult ActOnExprStmt(FullExprArg Expr) {
     return OwningStmtResult(*this, Expr->release());
   }
index 7637382ac032dc25175af40254f0066104cc19b2..ff08ebbe873523137542c557c9d2f1471aca471e 100644 (file)
@@ -944,6 +944,7 @@ Parser::OwningStmtResult Parser::ParseForStatement() {
     if (Tok.is(tok::semi)) {  // for (int x = 4;
       ConsumeToken();
     } else if ((ForEach = isTokIdentifier_in())) {
+      Actions.ActOnForEachDeclStmt(DG);
       // ObjC: for (id x in expr)
       ConsumeToken(); // consume 'in'
       SecondPart = ParseExpression();
index ad4c90bdc2a53e6c40eb93f252b8d61079cef85e..72039e275690cb8c4c7c051bab884eb45ccb43a9 100644 (file)
@@ -1260,6 +1260,7 @@ public:
   virtual OwningStmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
                                          SourceLocation StartLoc,
                                          SourceLocation EndLoc);
+  virtual void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
   virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
                                     SourceLocation DotDotDotLoc, ExprArg RHSVal,
                                     SourceLocation ColonLoc);
index d0f214fbd83dd4e824fc01bfac84e9584e0061ae..996056587711fa34947d1f13037c14e99938eac1 100644 (file)
@@ -59,6 +59,15 @@ Sema::OwningStmtResult Sema::ActOnDeclStmt(DeclGroupPtrTy dg,
   return Owned(new (Context) DeclStmt(DG, StartLoc, EndLoc));
 }
 
+void Sema::ActOnForEachDeclStmt(DeclGroupPtrTy dg) {
+  DeclGroupRef DG = dg.getAsVal<DeclGroupRef>();
+  
+  // If we have an invalid decl, just return.
+  if (DG.isNull() || !DG.isSingleDecl()) return;
+  // suppress any potential 'unused variable' warning.
+  DG.getSingleDecl()->setUsed();
+}
+
 void Sema::DiagnoseUnusedExprResult(const Stmt *S) {
   const Expr *E = dyn_cast_or_null<Expr>(S);
   if (!E)
index f136adfa363b04df400c2f217eb38142636d4678..2b62b1744ce276f4f28e9ddd0a94914147db6edb 100644 (file)
@@ -1,4 +1,4 @@
-/* RUN: clang-cc -fsyntax-only -verify -std=c89 -pedantic %s
+/* RUN: clang-cc -Wall -fsyntax-only -verify -std=c89 -pedantic %s
  */
 
 @class NSArray;