]> granicus.if.org Git - clang/commitdiff
ObjClang++: Allow declaration of block variable in a collection
authorFariborz Jahanian <fjahanian@apple.com>
Sun, 29 Aug 2010 17:20:53 +0000 (17:20 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Sun, 29 Aug 2010 17:20:53 +0000 (17:20 +0000)
statement header (fixes radar 8295106).

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

lib/Parse/ParseTentative.cpp
test/SemaObjCXX/foreach-block.mm [new file with mode: 0644]

index dcf1d40628994f64798fb766ca84b4d3b0754ccc..17273a0cf62be18f430e36cc5955031ab213c167 100644 (file)
@@ -188,7 +188,7 @@ Parser::TPResult Parser::TryParseInitDeclaratorList() {
       ConsumeParen();
       if (!SkipUntil(tok::r_paren))
         return TPResult::Error();
-    } else if (Tok.is(tok::equal)) {
+    } else if (Tok.is(tok::equal) || isTokIdentifier_in()) {
       // MSVC and g++ won't examine the rest of declarators if '=' is 
       // encountered; they just conclude that we have a declaration.
       // EDG parses the initializer completely, which is the proper behavior
@@ -197,6 +197,12 @@ Parser::TPResult Parser::TryParseInitDeclaratorList() {
       // At present, Clang follows MSVC and g++, since the parser does not have
       // the ability to parse an expression fully without recording the
       // results of that parse.
+      // Also allow 'in' after on objective-c declaration as in: 
+      // for (int (^b)(void) in array). Ideally this should be done in the 
+      // context of parsing for-init-statement of a foreach statement only. But,
+      // in any other context 'in' is invalid after a declaration and parser
+      // issues the error regardless of outcome of this decision.
+      // FIXME. Change if above assumption does not hold.
       return TPResult::True();
     }
 
diff --git a/test/SemaObjCXX/foreach-block.mm b/test/SemaObjCXX/foreach-block.mm
new file mode 100644 (file)
index 0000000..91bd0c8
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s
+// rdar://8295106
+
+int main() {
+id array;
+
+    for (int (^b)(void) in array) {
+        if (b() == 10000) {
+            return 1;
+        }
+    }
+
+    int (^b)(void) in array; // expected-error {{expected ';' at end of declaration}}
+}