]> granicus.if.org Git - clang/commitdiff
Issue diagnostics if more than one declaration in objectove-c's foreach-stmt header.
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 7 Jan 2008 17:52:35 +0000 (17:52 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 7 Jan 2008 17:52:35 +0000 (17:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45708 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaStmt.cpp
include/clang/Basic/DiagnosticKinds.def
test/Parser/objc-forcollection-neg-2.m [new file with mode: 0644]

index ab40e708e3663e976ffecf65676dff429886c12c..7219db2621e442ed5bb4ec2461e0f568388e8429 100644 (file)
@@ -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();
index 70acbbcc74dd285f6e3f7b5459ce8f3ecdf60e76..289f770ec69b47bd4389a13fb6c65cb82de34693 100644 (file)
@@ -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/test/Parser/objc-forcollection-neg-2.m b/test/Parser/objc-forcollection-neg-2.m
new file mode 100644 (file)
index 0000000..807efd9
--- /dev/null
@@ -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
+