diff options
author | Chris Lattner <sabre@nondot.org> | 2011-04-25 20:37:58 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-04-25 20:37:58 +0000 |
commit | 223de2497fdaacf3a6b0a123c12265ca837abf19 (patch) | |
tree | b6645879c663bca5308afcd245e1a1fdca17787f /lib/Sema/SemaTemplate.cpp | |
parent | 62c9258f4a71569a66d805fc7776526a2c76b34e (diff) |
fix PR9474, a crash with -fshort-enum and C++ templates: when instantiating
the enum decl, we need to use an integer type the same size as the enumerator,
which may not be the promoted type with packed enums.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130148 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplate.cpp')
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index bc29a4cbdc..3123f5fc67 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -3840,18 +3840,18 @@ Sema::BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, if (T->isCharType() || T->isWideCharType()) return Owned(new (Context) CharacterLiteral( Arg.getAsIntegral()->getZExtValue(), - T->isWideCharType(), - T, - Loc)); + T->isWideCharType(), T, Loc)); if (T->isBooleanType()) return Owned(new (Context) CXXBoolLiteralExpr( Arg.getAsIntegral()->getBoolValue(), - T, - Loc)); + T, Loc)); + // If this is an enum type that we're instantiating, we need to use an integer + // type the same size as the enumerator. We don't want to build an + // IntegerLiteral with enum type. QualType BT; if (const EnumType *ET = T->getAs<EnumType>()) - BT = ET->getDecl()->getPromotionType(); + BT = ET->getDecl()->getIntegerType(); else BT = T; @@ -3859,10 +3859,9 @@ Sema::BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, if (T->isEnumeralType()) { // FIXME: This is a hack. We need a better way to handle substituted // non-type template parameters. - E = CStyleCastExpr::Create(Context, T, VK_RValue, CK_IntegralCast, - E, 0, - Context.getTrivialTypeSourceInfo(T, Loc), - Loc, Loc); + E = CStyleCastExpr::Create(Context, T, VK_RValue, CK_IntegralCast, E, 0, + Context.getTrivialTypeSourceInfo(T, Loc), + Loc, Loc); } return Owned(E); |