aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2009-11-19 22:12:37 +0000
committerFariborz Jahanian <fjahanian@apple.com>2009-11-19 22:12:37 +0000
commita7cf23a72b0846fc5aacf3f38bb8c8f9e76784cf (patch)
treee01fa9aeac13c433fceb7efd292392d29434a886
parente24568725c04acaa4b7ff3db283e6098ad947847 (diff)
Don't issue spurious diagnostic with Obj-C fast enumeration.
(radar 7409165). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89400 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Parse/Action.h3
-rw-r--r--lib/Parse/ParseStmt.cpp1
-rw-r--r--lib/Sema/Sema.h1
-rw-r--r--lib/Sema/SemaStmt.cpp9
-rw-r--r--test/SemaObjC/foreach.m2
5 files changed, 15 insertions, 1 deletions
diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h
index 3d3232b6f6..45891bc0c9 100644
--- a/include/clang/Parse/Action.h
+++ b/include/clang/Parse/Action.h
@@ -668,6 +668,9 @@ public:
return StmtEmpty();
}
+ virtual void ActOnForEachDeclStmt(DeclGroupPtrTy Decl) {
+ }
+
virtual OwningStmtResult ActOnExprStmt(FullExprArg Expr) {
return OwningStmtResult(*this, Expr->release());
}
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index 7637382ac0..ff08ebbe87 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -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();
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index ad4c90bdc2..72039e2756 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -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);
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index d0f214fbd8..9960565877 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -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)
diff --git a/test/SemaObjC/foreach.m b/test/SemaObjC/foreach.m
index f136adfa36..2b62b1744c 100644
--- a/test/SemaObjC/foreach.m
+++ b/test/SemaObjC/foreach.m
@@ -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;