]> granicus.if.org Git - clang/commitdiff
Catch a foreach parse error.
authorFariborz Jahanian <fjahanian@apple.com>
Sat, 17 Jan 2009 00:00:40 +0000 (00:00 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Sat, 17 Jan 2009 00:00:40 +0000 (00:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62382 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseDecl.cpp
test/Parser/objc-foreach-syntax.m [new file with mode: 0644]

index 8d4705a7bf21a4ec0e7ed15c57f4c253e9e23333..be929ae067860d78c3ff0061de83b8fa6dacfe65 100644 (file)
@@ -364,6 +364,11 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) {
   
   if (Tok.is(tok::semi)) {
     ConsumeToken();
+    // for(is key; in keys) is error.
+    if (D.getContext()  == Declarator::ForContext && isTokIdentifier_in()) {
+      Diag(Tok, diag::err_parse_error);
+      return 0;
+    }
     return Actions.FinalizeDeclaratorGroup(CurScope, LastDeclInGroup);
   }
   // If this is an ObjC2 for-each loop, this is a successful declarator
diff --git a/test/Parser/objc-foreach-syntax.m b/test/Parser/objc-foreach-syntax.m
new file mode 100644 (file)
index 0000000..c00f777
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: clang -fsyntax-only -verify %s
+
+static int test_NSURLGetResourceValueForKey( id keys )
+{
+ for ( id key; in keys) {  // expected-error {{parse error}}
+  } 
+}