diff options
author | Douglas Gregor <dgregor@apple.com> | 2008-12-12 02:00:36 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2008-12-12 02:00:36 +0000 |
commit | 1d248c53ab1c5f84748f508017db55fe8e0fcbff (patch) | |
tree | c87a0be27ef385e0711a06d1629d12cab584100a /clang/lib/Sema/SemaDecl.cpp | |
parent | 9c2d26d2081721b030e006ca31b23efe6b5f0ba8 (diff) | |
download | bcm5719-llvm-1d248c53ab1c5f84748f508017db55fe8e0fcbff.tar.gz bcm5719-llvm-1d248c53ab1c5f84748f508017db55fe8e0fcbff.zip |
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
llvm-svn: 60917
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index fe53585aae8..43964f7ccad 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3176,6 +3176,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX, // 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 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX, 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 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX, 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 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX, // 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); |