aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaTemplate.cpp
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2010-12-15 15:06:14 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2010-12-15 15:06:14 +0000
commitfb7b36327c4cd14c9454e0e9c26f8c44ba8207c0 (patch)
treed2aa96e7731797a37e416019ea79cb036d054efa /lib/Sema/SemaTemplate.cpp
parentf24e54a0c8f0621dc1e964e79dd2fc47f6a2e723 (diff)
Sema: have BuildExpressionFromIntegralTemplateArgument produce well-formed IntegerLiterals
BuildExpressionFromIntegralTemplateArgument can produce malformed IntegerLiterals with an EnumType if the template parameter type is an EnumType. This breaks the AST printer which expects all IntegerLiterals to have a plain integer type. Instead, give the IntegerLiteral the enum's promotion type and wrap in an implicit cast to the EnumType. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121862 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplate.cpp')
-rw-r--r--lib/Sema/SemaTemplate.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index d38bffd9e3..088e0193a5 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -3463,7 +3463,16 @@ Sema::BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
T,
Loc));
- return Owned(IntegerLiteral::Create(Context, *Arg.getAsIntegral(), T, Loc));
+ QualType BT;
+ if (const EnumType *ET = T->getAs<EnumType>())
+ BT = ET->getDecl()->getPromotionType();
+ else
+ BT = T;
+
+ Expr *E = IntegerLiteral::Create(Context, *Arg.getAsIntegral(), BT, Loc);
+ ImpCastExprToType(E, T, CK_IntegralCast);
+
+ return Owned(E);
}