summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaOverload.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2009-12-09 09:09:27 +0000
committerJohn McCall <rjmccall@apple.com>2009-12-09 09:09:27 +0000
commit5677499fbffe3441543f2e0c2f7e4016270560a5 (patch)
treea2f87a1b1b6eb37c6fbf50caba31774a94c123a2 /clang/lib/Sema/SemaOverload.cpp
parent1d153328be1c52cf8d595bbd24ca829c2f8334d2 (diff)
downloadbcm5719-llvm-5677499fbffe3441543f2e0c2f7e4016270560a5.tar.gz
bcm5719-llvm-5677499fbffe3441543f2e0c2f7e4016270560a5.zip
First pass at implementing C++ enum semantics: calculate (and store) an
"integer promotion" type associated with an enum decl, and use this type to determine which type to promote to. This type obeys C++ [conv.prom]p2 and is therefore generally signed unless the range of the enumerators forces it to be unsigned. Kills off a lot of false positives from -Wsign-compare in C++, addressing rdar://7455616 llvm-svn: 90965
Diffstat (limited to 'clang/lib/Sema/SemaOverload.cpp')
-rw-r--r--clang/lib/Sema/SemaOverload.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 2555f5bde60..4443de05380 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -754,19 +754,21 @@ bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType) {
// can be converted to an rvalue of the first of the following types
// that can represent all the values of its underlying type: int,
// unsigned int, long, or unsigned long (C++ 4.5p2).
- if ((FromType->isEnumeralType() || FromType->isWideCharType())
- && ToType->isIntegerType()) {
+
+ // We pre-calculate the promotion type for enum types.
+ if (const EnumType *FromEnumType = FromType->getAs<EnumType>())
+ if (ToType->isIntegerType())
+ return Context.hasSameUnqualifiedType(ToType,
+ FromEnumType->getDecl()->getPromotionType());
+
+ if (FromType->isWideCharType() && ToType->isIntegerType()) {
// Determine whether the type we're converting from is signed or
// unsigned.
bool FromIsSigned;
uint64_t FromSize = Context.getTypeSize(FromType);
- if (const EnumType *FromEnumType = FromType->getAs<EnumType>()) {
- QualType UnderlyingType = FromEnumType->getDecl()->getIntegerType();
- FromIsSigned = UnderlyingType->isSignedIntegerType();
- } else {
- // FIXME: Is wchar_t signed or unsigned? We assume it's signed for now.
- FromIsSigned = true;
- }
+
+ // FIXME: Is wchar_t signed or unsigned? We assume it's signed for now.
+ FromIsSigned = true;
// The types we'll try to promote to, in the appropriate
// order. Try each of these types.
OpenPOWER on IntegriCloud