In C++, set the type of each of the enumerators in an enumeration to
the type of the enumeration once the enumeration has been defined.
Fix the overloading test-case to properly create enums that promote
the way we want them to.
Implement C++0x promotions from enumeration types to long
long/unsigned long long. We're using these promotions in Carbon.h
(since long long is a common extension).
Fixes PR clang/2954: http://llvm.org/bugs/show_bug.cgi?id=2954
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60917 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index fe53585..43964f7 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3176,6 +3176,7 @@
// Keep track of whether all elements have type int.
bool AllElementsInt = true;
+ QualType EnumType = Context.getTypeDeclType(Enum);
EnumConstantDecl *EltList = 0;
for (unsigned i = 0; i != NumElements; ++i) {
EnumConstantDecl *ECD =
@@ -3269,6 +3270,12 @@
llvm::APSInt IV = ECD->getInitVal();
IV.setIsSigned(true);
ECD->setInitVal(IV);
+
+ if (getLangOptions().CPlusPlus)
+ // C++ [dcl.enum]p4: Following the closing brace of an
+ // enum-specifier, each enumerator has the type of its
+ // enumeration.
+ ECD->setType(EnumType);
continue; // Already int type.
}
@@ -3291,6 +3298,11 @@
NewSign = true;
} else if (ECD->getType() == BestType) {
// Already the right type!
+ if (getLangOptions().CPlusPlus)
+ // C++ [dcl.enum]p4: Following the closing brace of an
+ // enum-specifier, each enumerator has the type of its
+ // enumeration.
+ ECD->setType(EnumType);
continue;
} else {
NewTy = BestType;
@@ -3306,7 +3318,13 @@
// Adjust the Expr initializer and type.
ECD->setInitExpr(new ImplicitCastExpr(NewTy, ECD->getInitExpr(),
/*isLvalue=*/false));
- ECD->setType(NewTy);
+ if (getLangOptions().CPlusPlus)
+ // C++ [dcl.enum]p4: Following the closing brace of an
+ // enum-specifier, each enumerator has the type of its
+ // enumeration.
+ ECD->setType(EnumType);
+ else
+ ECD->setType(NewTy);
}
Enum->completeDefinition(Context, BestType);