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
diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h
index 3d3232b..45891bc 100644
--- a/include/clang/Parse/Action.h
+++ b/include/clang/Parse/Action.h
@@ -668,6 +668,9 @@
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 7637382..ff08ebb 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -944,6 +944,7 @@
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 ad4c90b..72039e2 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -1260,6 +1260,7 @@
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 d0f214f..9960565 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -59,6 +59,15 @@
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 f136adf..2b62b17 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;