diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-05-15 18:53:42 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-05-15 18:53:42 +0000 |
commit | d06f6ca61062f85926eb9d409eb3d4f8afcf93c7 (patch) | |
tree | 9caf4b47278290f24aff828efc481b32c9a3aebb /lib/Sema/SemaTemplateInstantiateStmt.cpp | |
parent | 2e24661a0f880b88a6ececb9c32830c403067329 (diff) |
Template instantiation for "if" statements. Also:
- Skip semantic analysis of the "if" condition if it is type-dependent.
- Added the location of the "else" keyword into IfStmt, so that we can
provide it for type-checking after template instantiation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71875 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiateStmt.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateStmt.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/Sema/SemaTemplateInstantiateStmt.cpp b/lib/Sema/SemaTemplateInstantiateStmt.cpp index cbe4449efc..957402ac6f 100644 --- a/lib/Sema/SemaTemplateInstantiateStmt.cpp +++ b/lib/Sema/SemaTemplateInstantiateStmt.cpp @@ -39,6 +39,7 @@ namespace { OwningStmtResult VisitDeclStmt(DeclStmt *S); OwningStmtResult VisitNullStmt(NullStmt *S); OwningStmtResult VisitCompoundStmt(CompoundStmt *S); + OwningStmtResult VisitIfStmt(IfStmt *S); OwningStmtResult VisitExpr(Expr *E); OwningStmtResult VisitLabelStmt(LabelStmt *S); OwningStmtResult VisitGotoStmt(GotoStmt *S); @@ -135,6 +136,26 @@ TemplateStmtInstantiator::VisitCompoundStmt(CompoundStmt *S) { S->getRBracLoc())); } +Sema::OwningStmtResult TemplateStmtInstantiator::VisitIfStmt(IfStmt *S) { + // Instantiate the condition + OwningExprResult Cond = SemaRef.InstantiateExpr(S->getCond(), TemplateArgs); + if (Cond.isInvalid()) + return SemaRef.StmtError(); + + // Instantiate the "then" branch. + OwningStmtResult Then = SemaRef.InstantiateStmt(S->getThen(), TemplateArgs); + if (Then.isInvalid()) + return SemaRef.StmtError(); + + // Instantiate the "else" branch. + OwningStmtResult Else = SemaRef.InstantiateStmt(S->getElse(), TemplateArgs); + if (Else.isInvalid()) + return SemaRef.StmtError(); + + return SemaRef.ActOnIfStmt(S->getIfLoc(), move(Cond), move(Then), + S->getElseLoc(), move(Else)); +} + Sema::OwningStmtResult TemplateStmtInstantiator::VisitExpr(Expr *E) { Sema::OwningExprResult Result = SemaRef.InstantiateExpr(E, TemplateArgs); if (Result.isInvalid()) |