summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/Sema/SemaStmt.cpp5
-rw-r--r--clang/include/clang/Basic/DiagnosticKinds.def2
-rw-r--r--clang/test/Parser/objc-forcollection-neg-2.m38
3 files changed, 44 insertions, 1 deletions
diff --git a/clang/Sema/SemaStmt.cpp b/clang/Sema/SemaStmt.cpp
index ab40e708e36..7219db2621e 100644
--- a/clang/Sema/SemaStmt.cpp
+++ b/clang/Sema/SemaStmt.cpp
@@ -543,9 +543,12 @@ Sema::ActOnObjcForCollectionStmt(SourceLocation ForColLoc,
FirstType = 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'.
- BlockVarDecl *BVD = cast<BlockVarDecl>(DS->getDecl());
+ ScopedDecl *D = DS->getDecl();
+ BlockVarDecl *BVD = cast<BlockVarDecl>(D);
if (!BVD->hasLocalStorage())
return Diag(BVD->getLocation(), diag::err_non_variable_decl_in_for);
+ if (D->getNextDeclarator())
+ return Diag(D->getLocation(), diag::err_toomany_element_decls);
}
else
FirstType = static_cast<Expr*>(first)->getType();
diff --git a/clang/include/clang/Basic/DiagnosticKinds.def b/clang/include/clang/Basic/DiagnosticKinds.def
index 70acbbcc74d..289f770ec69 100644
--- a/clang/include/clang/Basic/DiagnosticKinds.def
+++ b/clang/include/clang/Basic/DiagnosticKinds.def
@@ -476,6 +476,8 @@ DIAG(err_collection_expr_type, ERROR,
"collection expression is not of valid object type (its type is '%0')")
DIAG(err_selector_element_type, ERROR,
"selector element is not of valid object type (its type is '%0')")
+DIAG(err_toomany_element_decls, ERROR,
+ "Only one element declaration is allowed")
//===----------------------------------------------------------------------===//
// Semantic Analysis
diff --git a/clang/test/Parser/objc-forcollection-neg-2.m b/clang/test/Parser/objc-forcollection-neg-2.m
new file mode 100644
index 00000000000..807efd9fa71
--- /dev/null
+++ b/clang/test/Parser/objc-forcollection-neg-2.m
@@ -0,0 +1,38 @@
+// RUN: clang -fsyntax-only -verify %s
+
+typedef struct objc_class *Class;
+typedef struct objc_object {
+ Class isa;
+} *id;
+
+
+@protocol P @end
+
+@interface MyList
+@end
+
+@implementation MyList
+- (unsigned int)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state objects: (id *)items count:(unsigned int)stackcount
+{
+ return 0;
+}
+@end
+
+@interface MyList (BasicTest)
+- (void)compilerTestAgainst;
+@end
+
+@implementation MyList (BasicTest)
+- (void)compilerTestAgainst {
+ static i;
+ for (id el, elem in self) // expected-error {{Only one element declaration is allowed}}
+ ++i;
+ for (id el in self)
+ ++i;
+ MyList<P> ***p;
+ for (p in self)
+ ++i;
+
+}
+@end
+
OpenPOWER on IntegriCloud