[cfe-commits] r91089 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaTemplate/instantiate-enum-2.cpp

Eli Friedman eli.friedman at gmail.com
Thu Dec 10 17:34:50 PST 2009


Author: efriedma
Date: Thu Dec 10 19:34:50 2009
New Revision: 91089

URL: http://llvm.org/viewvc/llvm-project?rev=91089&view=rev
Log:
Fix the handling of dependent enums per C++ DR 502.


Added:
    cfe/trunk/test/SemaTemplate/instantiate-enum-2.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=91089&r1=91088&r2=91089&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Dec 10 19:34:50 2009
@@ -5663,7 +5663,7 @@
   llvm::APSInt EnumVal(32);
   QualType EltTy;
   if (Val) {
-    if (Val->isTypeDependent())
+    if (Enum->isDependentType())
       EltTy = Context.DependentTy;
     else {
       // Make sure to promote the operand type to int.
@@ -5675,8 +5675,7 @@
 
       // C99 6.7.2.2p2: Make sure we have an integer constant expression.
       SourceLocation ExpLoc;
-      if (!Val->isValueDependent() &&
-          VerifyIntegerConstantExpression(Val, &EnumVal)) {
+      if (VerifyIntegerConstantExpression(Val, &EnumVal)) {
         Val = 0;
       } else {
         EltTy = Val->getType();
@@ -5685,7 +5684,9 @@
   }
 
   if (!Val) {
-    if (LastEnumConst) {
+    if (Enum->isDependentType())
+      EltTy = Context.DependentTy;
+    else if (LastEnumConst) {
       // Assign the last value + 1.
       EnumVal = LastEnumConst->getInitVal();
       ++EnumVal;
@@ -5771,6 +5772,19 @@
   if (Attr)
     ProcessDeclAttributeList(S, Enum, Attr);
 
+  if (Enum->isDependentType()) {
+    for (unsigned i = 0; i != NumElements; ++i) {
+      EnumConstantDecl *ECD =
+        cast_or_null<EnumConstantDecl>(Elements[i].getAs<Decl>());
+      if (!ECD) continue;
+
+      ECD->setType(EnumType);
+    }
+
+    Enum->completeDefinition(Context, Context.DependentTy, Context.DependentTy);
+    return;
+  }
+
   // TODO: If the result value doesn't fit in an int, it must be a long or long
   // long value.  ISO C does not support this, but GCC does as an extension,
   // emit a warning.

Added: cfe/trunk/test/SemaTemplate/instantiate-enum-2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-enum-2.cpp?rev=91089&view=auto

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-enum-2.cpp (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-enum-2.cpp Thu Dec 10 19:34:50 2009
@@ -0,0 +1,9 @@
+// RUN: clang-cc %s -fsyntax-only -verify
+
+template<int IntBits> struct X {
+  enum {
+    IntShift = (unsigned long long)IntBits,
+    ShiftedIntMask = (1 << IntShift)
+  };
+};
+X<1> x;





More information about the cfe-commits mailing list