From 36bb03b86ab6f905b336ee9ec11f288291b22b45 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 21 May 2009 18:55:48 +0000 Subject: [PATCH] Template instantiation for unary type traits, e.g., __is_pod git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72220 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateInstantiateExpr.cpp | 19 ++++++++++++++++++- test/SemaTemplate/instantiate-expr-4.cpp | 11 +++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp index 2a1ee886b5..8cd60edb67 100644 --- a/lib/Sema/SemaTemplateInstantiateExpr.cpp +++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp @@ -90,7 +90,7 @@ namespace { OwningExprResult VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E); OwningExprResult VisitCXXNewExpr(CXXNewExpr *E); OwningExprResult VisitCXXDeleteExpr(CXXDeleteExpr *E); - // FIXME: UnaryTypeTraitExpr + OwningExprResult VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E); // FIXME: QualifiedDeclRefExpr OwningExprResult VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E); OwningExprResult VisitCXXUnresolvedConstructExpr( @@ -991,6 +991,23 @@ TemplateExprInstantiator::VisitCXXDeleteExpr(CXXDeleteExpr *E) { move(Operand)); } +Sema::OwningExprResult +TemplateExprInstantiator::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { + QualType T = SemaRef.InstantiateType(E->getQueriedType(), TemplateArgs, + /*FIXME*/E->getSourceRange().getBegin(), + DeclarationName()); + if (T.isNull()) + return SemaRef.ExprError(); + + SourceLocation FakeLParenLoc + = SemaRef.PP.getLocForEndOfToken(E->getSourceRange().getBegin()); + return SemaRef.ActOnUnaryTypeTrait(E->getTrait(), + E->getSourceRange().getBegin(), + /*FIXME*/FakeLParenLoc, + T.getAsOpaquePtr(), + E->getSourceRange().getEnd()); +} + Sema::OwningExprResult TemplateExprInstantiator::VisitCXXExprWithTemporaries( CXXExprWithTemporaries *E) { diff --git a/test/SemaTemplate/instantiate-expr-4.cpp b/test/SemaTemplate/instantiate-expr-4.cpp index 1511c7aaf8..5c32d8c197 100644 --- a/test/SemaTemplate/instantiate-expr-4.cpp +++ b/test/SemaTemplate/instantiate-expr-4.cpp @@ -139,3 +139,14 @@ struct Abstract { template struct TypeId0; template struct TypeId0; template struct TypeId0; + +// --------------------------------------------------------------------- +// type traits +// --------------------------------------------------------------------- +template +struct is_pod { + static const bool value = __is_pod(T); +}; + +static const int is_pod0[is_pod::value? -1 : 1]; +static const int is_pod1[is_pod::value? 1 : -1]; -- 2.40.0