From: Richard Smith Date: Mon, 18 Apr 2011 15:49:25 +0000 (+0000) Subject: Fix PR9741. The implicit declarations created for range-based for loops weren't being... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b403d6d746239095a2c7bac958c924d92434e2b4;p=clang Fix PR9741. The implicit declarations created for range-based for loops weren't being added to the DeclContext (nor were they being marked as implicit). Also, the declarations were being emitted in the wrong order when building the CFG. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129700 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index bfe2247fba..eaab487d95 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -2629,8 +2629,8 @@ CFGBlock* CFGBuilder::VisitCXXForRangeStmt(CXXForRangeStmt* S) { // Add the initialization statements. Block = createBlock(); - addStmt(S->getRangeStmt()); - return addStmt(S->getBeginEndStmt()); + addStmt(S->getBeginEndStmt()); + return addStmt(S->getRangeStmt()); } CFGBlock *CFGBuilder::VisitExprWithCleanups(ExprWithCleanups *E, diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 407618219f..e6609c08e2 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -1029,6 +1029,7 @@ static VarDecl *BuildForRangeVarDecl(Sema &SemaRef, SourceLocation Loc, TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); VarDecl *Decl = VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_Auto, SC_None); + Decl->setImplicit(); return Decl; } @@ -1052,6 +1053,7 @@ static bool FinishForRangeVarDecl(Sema &SemaRef, VarDecl *Decl, Expr *Init, SemaRef.AddInitializerToDecl(Decl, Init, /*DirectInit=*/false, /*TypeMayContainAuto=*/false); SemaRef.FinalizeDeclaration(Decl); + SemaRef.CurContext->addHiddenDecl(Decl); return false; } diff --git a/test/Analysis/PR9741.cpp b/test/Analysis/PR9741.cpp new file mode 100644 index 0000000000..e20e56c940 --- /dev/null +++ b/test/Analysis/PR9741.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -cc1 -std=c++0x -Wuninitialized -verify %s + +void f() { + int a[] = { 1, 2, 3 }; + unsigned int u = 0; + for (auto x : a) + ; +}