[cfe-commits] r86197 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaTemplate/enum-argument.cpp
Douglas Gregor
dgregor at apple.com
Thu Nov 5 16:03:12 PST 2009
Author: dgregor
Date: Thu Nov 5 18:03:12 2009
New Revision: 86197
URL: http://llvm.org/viewvc/llvm-project?rev=86197&view=rev
Log:
Make sure that EnumConstantDecls always get a type, even when they have type-dependent initializers.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaTemplate/enum-argument.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=86197&r1=86196&r2=86197&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Nov 5 18:03:12 2009
@@ -5362,21 +5362,25 @@
llvm::APSInt EnumVal(32);
QualType EltTy;
- if (Val && !Val->isTypeDependent()) {
- // Make sure to promote the operand type to int.
- UsualUnaryConversions(Val);
- if (Val != val.get()) {
- val.release();
- val = Val;
- }
+ if (Val) {
+ if (Val->isTypeDependent())
+ EltTy = Context.DependentTy;
+ else {
+ // Make sure to promote the operand type to int.
+ UsualUnaryConversions(Val);
+ if (Val != val.get()) {
+ val.release();
+ val = Val;
+ }
- // C99 6.7.2.2p2: Make sure we have an integer constant expression.
- SourceLocation ExpLoc;
- if (!Val->isValueDependent() &&
- VerifyIntegerConstantExpression(Val, &EnumVal)) {
- Val = 0;
- } else {
- EltTy = Val->getType();
+ // C99 6.7.2.2p2: Make sure we have an integer constant expression.
+ SourceLocation ExpLoc;
+ if (!Val->isValueDependent() &&
+ VerifyIntegerConstantExpression(Val, &EnumVal)) {
+ Val = 0;
+ } else {
+ EltTy = Val->getType();
+ }
}
}
@@ -5398,6 +5402,8 @@
}
}
+ assert(!EltTy.isNull() && "Enum constant with NULL type");
+
val.release();
return EnumConstantDecl::Create(Context, Enum, IdLoc, Id, EltTy,
Val, EnumVal);
Modified: cfe/trunk/test/SemaTemplate/enum-argument.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/enum-argument.cpp?rev=86197&r1=86196&r2=86197&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/enum-argument.cpp (original)
+++ cfe/trunk/test/SemaTemplate/enum-argument.cpp Thu Nov 5 18:03:12 2009
@@ -5,3 +5,19 @@
typedef C<v> Self;
};
template struct C<val>;
+
+template<typename T>
+struct get_size {
+ static const unsigned value = sizeof(T);
+};
+
+template<typename T>
+struct X0 {
+ enum {
+ Val1 = get_size<T>::value,
+ Val2,
+ SumOfValues = Val1 + Val2
+ };
+};
+
+X0<int> x0i;
More information about the cfe-commits
mailing list