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.

llvm-svn: 121862
This commit is contained in:
Peter Collingbourne 2010-12-15 15:06:14 +00:00
parent 0a2c416894
commit 03007d79fe
2 changed files with 16 additions and 1 deletions

View File

@ -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);
}

View File

@ -19,3 +19,9 @@ class Base1 {
class Base2 { };
class Derived1 : Base1, virtual public Base2 { };
/* Template classes, template functions */
enum E1 { EC1 };
template <E1 v> class C1 {};
template <E1 v> C1<v> f1() { return C1<v>(); }
void f2() { f1<EC1>(); }