From 9d73cabf22b970ec47eaae9b01ca55430f426618 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 15 May 2009 18:53:42 +0000 Subject: 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. llvm-svn: 71875 --- clang/lib/Sema/SemaTemplateInstantiateStmt.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'clang/lib/Sema/SemaTemplateInstantiateStmt.cpp') diff --git a/clang/lib/Sema/SemaTemplateInstantiateStmt.cpp b/clang/lib/Sema/SemaTemplateInstantiateStmt.cpp index cbe4449efcd..957402ac6f6 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateStmt.cpp +++ b/clang/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()) -- cgit v1.2.3