]> granicus.if.org Git - clang/commitdiff
Make sure that EnumConstantDecls always get a type, even when they have type-dependen...
authorDouglas Gregor <dgregor@apple.com>
Fri, 6 Nov 2009 00:03:12 +0000 (00:03 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 6 Nov 2009 00:03:12 +0000 (00:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86197 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaTemplate/enum-argument.cpp

index 088c7dc780717ca1a6cb082b6dbade877bc21397..0616fca6b8cb7eab61c567cc0f5ce7a946ba2571 100644 (file)
@@ -5362,21 +5362,25 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
 
   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 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
     }
   }
 
+  assert(!EltTy.isNull() && "Enum constant with NULL type");
+  
   val.release();
   return EnumConstantDecl::Create(Context, Enum, IdLoc, Id, EltTy,
                                   Val, EnumVal);
index 101a1d0cd9da13d99b589374835e200073d24435..1d782df202e398e4684f12099f447c9ad385335a 100644 (file)
@@ -5,3 +5,19 @@ template <Enum v> struct C {
   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;