From c6c14e56e34864c5d9343d9ea62ab688cf301eee Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Tue, 31 Jan 2012 22:45:40 +0000 Subject: [PATCH] A couple minor fixes to template instantiation for for-range loops. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149440 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/TreeTransform.h | 8 ++++++++ test/SemaCXX/for-range-examples.cpp | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index a6777ec5d8..0c0bd57b7f 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -5738,10 +5738,18 @@ TreeTransform::TransformCXXForRangeStmt(CXXForRangeStmt *S) { ExprResult Cond = getDerived().TransformExpr(S->getCond()); if (Cond.isInvalid()) return StmtError(); + if (Cond.get()) + Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc()); + if (Cond.isInvalid()) + return StmtError(); + if (Cond.get()) + Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take()); ExprResult Inc = getDerived().TransformExpr(S->getInc()); if (Inc.isInvalid()) return StmtError(); + if (Inc.get()) + Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take()); StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); if (LoopVar.isInvalid()) diff --git a/test/SemaCXX/for-range-examples.cpp b/test/SemaCXX/for-range-examples.cpp index dd356032cf..868de9d4f0 100644 --- a/test/SemaCXX/for-range-examples.cpp +++ b/test/SemaCXX/for-range-examples.cpp @@ -158,3 +158,14 @@ namespace test2 { for (int x : a.xs) { } // expected-error {{'xs' is a private member of 'test2::A'}} } } + +namespace test3 { + // Make sure this doesn't crash + struct A {}; + struct B { ~B(); operator bool(); }; + struct C { B operator!=(const C&); C& operator++(); int operator*(); }; + C begin(const A&); + C end(const A&); + template void f() { for (auto a : A()) {} } + void g() { f(); } +} -- 2.40.0