diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-02-18 03:01:41 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-02-18 03:01:41 +0000 |
commit | b327eac1176a91b90b4755ec4b152ba42c0e2059 (patch) | |
tree | 07c79da0668fe27016ac137b419fe02e25f2790c /clang/lib/Sema/SemaCXXCast.cpp | |
parent | 53049153cf044fc34e8d1f5516dff6ee7a4d0712 (diff) | |
download | bcm5719-llvm-b327eac1176a91b90b4755ec4b152ba42c0e2059.tar.gz bcm5719-llvm-b327eac1176a91b90b4755ec4b152ba42c0e2059.zip |
Implement C++0x [expr.static.cast]p9, which permits explicitly casting
a scoped enumeration type to an integral or floating type,
properly. There was an over-eager assertion, and it was missing the
floating-point case.
Fixes PR9107/<rdar://problem/8937402>.
llvm-svn: 125825
Diffstat (limited to 'clang/lib/Sema/SemaCXXCast.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCXXCast.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/clang/lib/Sema/SemaCXXCast.cpp b/clang/lib/Sema/SemaCXXCast.cpp index 35b7f51df1c..30bb5763f21 100644 --- a/clang/lib/Sema/SemaCXXCast.cpp +++ b/clang/lib/Sema/SemaCXXCast.cpp @@ -688,18 +688,23 @@ static TryCastResult TryStaticCast(Sema &Self, Expr *&SrcExpr, QualType SrcType = Self.Context.getCanonicalType(SrcExpr->getType()); // C++0x 5.2.9p9: A value of a scoped enumeration type can be explicitly - // converted to an integral type. - if (Self.getLangOptions().CPlusPlus0x && SrcType->isEnumeralType()) { - assert(SrcType->getAs<EnumType>()->getDecl()->isScoped()); - if (DestType->isBooleanType()) { - Kind = CK_IntegralToBoolean; - return TC_Success; - } else if (DestType->isIntegralType(Self.Context)) { - Kind = CK_IntegralCast; - return TC_Success; + // converted to an integral type. [...] A value of a scoped enumeration type + // can also be explicitly converted to a floating-point type [...]. + if (const EnumType *Enum = SrcType->getAs<EnumType>()) { + if (Enum->getDecl()->isScoped()) { + if (DestType->isBooleanType()) { + Kind = CK_IntegralToBoolean; + return TC_Success; + } else if (DestType->isIntegralType(Self.Context)) { + Kind = CK_IntegralCast; + return TC_Success; + } else if (DestType->isRealFloatingType()) { + Kind = CK_IntegralToFloating; + return TC_Success; + } } } - + // Reverse integral promotion/conversion. All such conversions are themselves // again integral promotions or conversions and are thus already handled by // p2 (TryDirectInitialization above). |