diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-05-15 21:45:53 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-05-15 21:45:53 +0000 |
commit | 4a2e2041edc63db687677325e113b39b9d123c40 (patch) | |
tree | 49fb2aa5b377050c0f3eef363fde77b979f2e088 | |
parent | 49f25ecf7ff358039ce4c9254b867f32110e660e (diff) |
Template instantiation for WhileStmt and CXXConditionDeclExpr.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71896 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/ExprCXX.h | 5 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 24 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateExpr.cpp | 16 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateStmt.cpp | 15 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-function-1.cpp | 11 |
5 files changed, 59 insertions, 12 deletions
diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index c34ded26a5..b6a970e231 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -564,7 +564,10 @@ public: CXXConditionDeclExpr(SourceLocation startLoc, SourceLocation eqLoc, VarDecl *var) : DeclRefExpr(CXXConditionDeclExprClass, var, - var->getType().getNonReferenceType(), startLoc) {} + var->getType().getNonReferenceType(), startLoc, + var->getType()->isDependentType(), + /*FIXME:integral constant?*/ + var->getType()->isDependentType()) {} virtual void Destroy(ASTContext& Ctx); diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index a5277a9293..652e2a6e0f 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -520,17 +520,19 @@ Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond, StmtArg Body) { Expr *condExpr = Cond.takeAs<Expr>(); assert(condExpr && "ActOnWhileStmt(): missing expression"); - DefaultFunctionArrayConversion(condExpr); - Cond = condExpr; - QualType condType = condExpr->getType(); - - if (getLangOptions().CPlusPlus) { - if (CheckCXXBooleanCondition(condExpr)) // C++ 6.4p4 - return StmtError(); - } else if (!condType->isScalarType()) // C99 6.8.5p2 - return StmtError(Diag(WhileLoc, - diag::err_typecheck_statement_requires_scalar) - << condType << condExpr->getSourceRange()); + if (!condExpr->isTypeDependent()) { + DefaultFunctionArrayConversion(condExpr); + Cond = condExpr; + QualType condType = condExpr->getType(); + + if (getLangOptions().CPlusPlus) { + if (CheckCXXBooleanCondition(condExpr)) // C++ 6.4p4 + return StmtError(); + } else if (!condType->isScalarType()) // C99 6.8.5p2 + return StmtError(Diag(WhileLoc, + diag::err_typecheck_statement_requires_scalar) + << condType << condExpr->getSourceRange()); + } Cond.release(); return Owned(new (Context) WhileStmt(condExpr, Body.takeAs<Stmt>(), diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp index 08c388efea..53e42fc529 100644 --- a/lib/Sema/SemaTemplateInstantiateExpr.cpp +++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp @@ -42,6 +42,7 @@ namespace { OwningExprResult VisitUnaryOperator(UnaryOperator *E); OwningExprResult VisitBinaryOperator(BinaryOperator *E); OwningExprResult VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E); + OwningExprResult VisitCXXConditionDeclExpr(CXXConditionDeclExpr *E); OwningExprResult VisitConditionalOperator(ConditionalOperator *E); OwningExprResult VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E); OwningExprResult VisitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *E); @@ -262,6 +263,21 @@ TemplateExprInstantiator::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) { return move(Result); } +Sema::OwningExprResult +TemplateExprInstantiator::VisitCXXConditionDeclExpr(CXXConditionDeclExpr *E) { + VarDecl *Var + = cast_or_null<VarDecl>(SemaRef.InstantiateDecl(E->getVarDecl(), + SemaRef.CurContext, + TemplateArgs)); + if (!Var) + return SemaRef.ExprError(); + + return SemaRef.Owned(new (SemaRef.Context) CXXConditionDeclExpr( + E->getStartLoc(), + SourceLocation(), + Var)); +} + Sema::OwningExprResult TemplateExprInstantiator::VisitConditionalOperator(ConditionalOperator *E) { Sema::OwningExprResult Cond = Visit(E->getCond()); diff --git a/lib/Sema/SemaTemplateInstantiateStmt.cpp b/lib/Sema/SemaTemplateInstantiateStmt.cpp index 2a3f48a469..9a4d75e117 100644 --- a/lib/Sema/SemaTemplateInstantiateStmt.cpp +++ b/lib/Sema/SemaTemplateInstantiateStmt.cpp @@ -40,6 +40,7 @@ namespace { OwningStmtResult VisitNullStmt(NullStmt *S); OwningStmtResult VisitCompoundStmt(CompoundStmt *S); OwningStmtResult VisitIfStmt(IfStmt *S); + OwningStmtResult VisitWhileStmt(WhileStmt *S); OwningStmtResult VisitExpr(Expr *E); OwningStmtResult VisitLabelStmt(LabelStmt *S); OwningStmtResult VisitGotoStmt(GotoStmt *S); @@ -156,6 +157,20 @@ Sema::OwningStmtResult TemplateStmtInstantiator::VisitIfStmt(IfStmt *S) { S->getElseLoc(), move(Else)); } +Sema::OwningStmtResult TemplateStmtInstantiator::VisitWhileStmt(WhileStmt *S) { + // Instantiate the condition + OwningExprResult Cond = SemaRef.InstantiateExpr(S->getCond(), TemplateArgs); + if (Cond.isInvalid()) + return SemaRef.StmtError(); + + // Instantiate the body + OwningStmtResult Body = SemaRef.InstantiateStmt(S->getBody(), TemplateArgs); + if (Body.isInvalid()) + return SemaRef.StmtError(); + + return SemaRef.ActOnWhileStmt(S->getWhileLoc(), move(Cond), move(Body)); +} + Sema::OwningStmtResult TemplateStmtInstantiator::VisitExpr(Expr *E) { Sema::OwningExprResult Result = SemaRef.InstantiateExpr(E, TemplateArgs); if (Result.isInvalid()) diff --git a/test/SemaTemplate/instantiate-function-1.cpp b/test/SemaTemplate/instantiate-function-1.cpp index e7c4af163a..3b88700c54 100644 --- a/test/SemaTemplate/instantiate-function-1.cpp +++ b/test/SemaTemplate/instantiate-function-1.cpp @@ -87,3 +87,14 @@ template <typename T> struct X7 { }; template struct X7<int>; + +template<typename T> struct While0 { + void f(T t) { + while (t) { + } + + while (T t2 = T()) ; + } +}; + +template struct While0<float>; |