[cfe-commits] r121862 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp test/Coverage/cxx-language-features.inc
Peter Collingbourne
peter at pcc.me.uk
Wed Dec 15 07:06:14 PST 2010
Author: pcc
Date: Wed Dec 15 09:06:14 2010
New Revision: 121862
URL: http://llvm.org/viewvc/llvm-project?rev=121862&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/Coverage/cxx-language-features.inc
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=121862&r1=121861&r2=121862&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Dec 15 09:06:14 2010
@@ -3463,7 +3463,16 @@
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);
}
Modified: cfe/trunk/test/Coverage/cxx-language-features.inc
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/cxx-language-features.inc?rev=121862&r1=121861&r2=121862&view=diff
==============================================================================
--- cfe/trunk/test/Coverage/cxx-language-features.inc (original)
+++ cfe/trunk/test/Coverage/cxx-language-features.inc Wed Dec 15 09:06:14 2010
@@ -19,3 +19,9 @@
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>(); }
More information about the cfe-commits
mailing list