[cfe-commits] r60917 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaOverload.cpp test/SemaCXX/overload-call.cpp
Douglas Gregor
dgregor at apple.com
Thu Dec 11 18:00:38 PST 2008
Author: dgregor
Date: Thu Dec 11 20:00:36 2008
New Revision: 60917
URL: http://llvm.org/viewvc/llvm-project?rev=60917&view=rev
Log:
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
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/SemaCXX/overload-call.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=60917&r1=60916&r2=60917&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Dec 11 20:00:36 2008
@@ -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);
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=60917&r1=60916&r2=60917&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Dec 11 20:00:36 2008
@@ -634,11 +634,12 @@
// The types we'll try to promote to, in the appropriate
// order. Try each of these types.
- QualType PromoteTypes[4] = {
+ QualType PromoteTypes[6] = {
Context.IntTy, Context.UnsignedIntTy,
- Context.LongTy, Context.UnsignedLongTy
+ Context.LongTy, Context.UnsignedLongTy ,
+ Context.LongLongTy, Context.UnsignedLongLongTy
};
- for (int Idx = 0; Idx < 4; ++Idx) {
+ for (int Idx = 0; Idx < 6; ++Idx) {
uint64_t ToSize = Context.getTypeSize(PromoteTypes[Idx]);
if (FromSize < ToSize ||
(FromSize == ToSize &&
@@ -2034,6 +2035,7 @@
CandidateSet.push_back(OverloadCandidate());
OverloadCandidate& Candidate = CandidateSet.back();
Candidate.Function = 0;
+ Candidate.IsSurrogate = false;
Candidate.BuiltinTypes.ResultTy = ResultTy;
for (unsigned ArgIdx = 0; ArgIdx < NumArgs; ++ArgIdx)
Candidate.BuiltinTypes.ParamTypes[ArgIdx] = ParamTys[ArgIdx];
Modified: cfe/trunk/test/SemaCXX/overload-call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overload-call.cpp?rev=60917&r1=60916&r2=60917&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/overload-call.cpp (original)
+++ cfe/trunk/test/SemaCXX/overload-call.cpp Thu Dec 11 20:00:36 2008
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -pedantic -verify %s
+// RUN: clang -fsyntax-only -pedantic -verify %s
int* f(int) { return 0; }
float* f(float) { return 0; }
void f();
@@ -88,11 +88,11 @@
}
enum PromotesToInt {
- PromotesToIntValue = 1
+ PromotesToIntValue = -1
};
enum PromotesToUnsignedInt {
- PromotesToUnsignedIntValue = (unsigned int)-1
+ PromotesToUnsignedIntValue = 1u
};
int* o(int);
More information about the cfe-commits
mailing list