From: Ted Kremenek Date: Mon, 6 Oct 2008 20:58:11 +0000 (+0000) Subject: When processing Objective-C foreach statements, first check to see if the statement... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f34afeed9a0112bf31fee185b6c80556111d3834;p=clang When processing Objective-C foreach statements, first check to see if the statement has a DeclStmt with a single Decl. Afterwards, use DeclStmt::getSolitaryDecl() to access that Decl (thus avoiding an assertion being triggered). These changes remove an unneeded use of ScopedDecl::getNextDeclarator() and DeclStmt::getDecl(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57207 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index cb61ce969b..68b36ba818 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -589,15 +589,17 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, if (First) { QualType FirstType; if (DeclStmt *DS = dyn_cast(First)) { - FirstType = cast(DS->getDecl())->getType(); + if (!DS->hasSolitaryDecl()) + return Diag((*DS->decl_begin())->getLocation(), + diag::err_toomany_element_decls); + + ScopedDecl *D = DS->getSolitaryDecl(); + FirstType = cast(D)->getType(); // C99 6.8.5p3: The declaration part of a 'for' statement shall only declare // identifiers for objects having storage class 'auto' or 'register'. - ScopedDecl *D = DS->getDecl(); VarDecl *VD = cast(D); if (VD->isBlockVarDecl() && !VD->hasLocalStorage()) return Diag(VD->getLocation(), diag::err_non_variable_decl_in_for); - if (D->getNextDeclarator()) - return Diag(D->getLocation(), diag::err_toomany_element_decls); } else { Expr::isLvalueResult lval = cast(First)->isLvalue(Context);