[cfe-commits] r45708 - in /cfe/trunk: Sema/SemaStmt.cpp include/clang/Basic/DiagnosticKinds.def test/Parser/objc-forcollection-neg-2.m

Fariborz Jahanian fjahanian at apple.com
Mon Jan 7 09:52:36 PST 2008


Author: fjahanian
Date: Mon Jan  7 11:52:35 2008
New Revision: 45708

URL: http://llvm.org/viewvc/llvm-project?rev=45708&view=rev
Log:
Issue diagnostics if more than one declaration in objectove-c's foreach-stmt header.

Added:
    cfe/trunk/test/Parser/objc-forcollection-neg-2.m
Modified:
    cfe/trunk/Sema/SemaStmt.cpp
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def

Modified: cfe/trunk/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaStmt.cpp?rev=45708&r1=45707&r2=45708&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/Sema/SemaStmt.cpp Mon Jan  7 11:52:35 2008
@@ -543,9 +543,12 @@
     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();

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=45708&r1=45707&r2=45708&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Mon Jan  7 11:52:35 2008
@@ -476,6 +476,8 @@
      "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

Added: cfe/trunk/test/Parser/objc-forcollection-neg-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-forcollection-neg-2.m?rev=45708&view=auto

==============================================================================
--- cfe/trunk/test/Parser/objc-forcollection-neg-2.m (added)
+++ cfe/trunk/test/Parser/objc-forcollection-neg-2.m Mon Jan  7 11:52:35 2008
@@ -0,0 +1,38 @@
+// RUN: clang -fsyntax-only -verify %s
+
+typedef struct objc_class *Class;
+typedef struct objc_object {
+ Class isa;
+} *id;
+    
+            
+ at protocol P @end
+
+ at interface MyList
+ at end
+    
+ at implementation MyList
+- (unsigned int)countByEnumeratingWithState:  (struct __objcFastEnumerationState *)state objects:  (id *)items count:(unsigned int)stackcount
+{
+        return 0;
+}
+ at end
+
+ at interface MyList (BasicTest)
+- (void)compilerTestAgainst;
+ at end
+
+ at 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;
+
+}
+ at end
+





More information about the cfe-commits mailing list