From: Fariborz Jahanian Date: Mon, 7 Jan 2008 17:52:35 +0000 (+0000) Subject: Issue diagnostics if more than one declaration in objectove-c's foreach-stmt header. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ce5da30642cd23968daf5bc2af5f6cd658c9c16;p=clang Issue diagnostics if more than one declaration in objectove-c's foreach-stmt header. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45708 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaStmt.cpp b/Sema/SemaStmt.cpp index ab40e708e3..7219db2621 100644 --- a/Sema/SemaStmt.cpp +++ b/Sema/SemaStmt.cpp @@ -543,9 +543,12 @@ Sema::ActOnObjcForCollectionStmt(SourceLocation ForColLoc, FirstType = cast(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(DS->getDecl()); + ScopedDecl *D = DS->getDecl(); + BlockVarDecl *BVD = cast(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(first)->getType(); diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 70acbbcc74..289f770ec6 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/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/test/Parser/objc-forcollection-neg-2.m b/test/Parser/objc-forcollection-neg-2.m new file mode 100644 index 0000000000..807efd9fa7 --- /dev/null +++ b/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; + for (p in self) + ++i; + +} +@end +