aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaCXXCast.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-01-26 21:04:06 +0000
committerDouglas Gregor <dgregor@apple.com>2011-01-26 21:04:06 +0000
commit8ec14e605725a87991f622d63f547f877ba59fef (patch)
tree7e50b9efb2a6e7546043ba1105654c943a6534d3 /lib/Sema/SemaCXXCast.cpp
parent1f3810623fc7adbff149585a49a3f174dafdea81 (diff)
Handle C-style casts to rvalue reference types that cast away constness.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124319 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaCXXCast.cpp')
-rw-r--r--lib/Sema/SemaCXXCast.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp
index 3a9ad5ff7f..c492c2ac7d 100644
--- a/lib/Sema/SemaCXXCast.cpp
+++ b/lib/Sema/SemaCXXCast.cpp
@@ -78,7 +78,8 @@ static bool CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType);
// %1: Source Type
// %2: Destination Type
static TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr,
- QualType DestType, CastKind &Kind,
+ QualType DestType, bool CStyle,
+ CastKind &Kind,
CXXCastPath &BasePath,
unsigned &msg);
static TryCastResult TryStaticReferenceDowncast(Sema &Self, Expr *SrcExpr,
@@ -583,7 +584,8 @@ static TryCastResult TryStaticCast(Sema &Self, Expr *&SrcExpr,
// C++0x [expr.static.cast]p3:
// A glvalue of type "cv1 T1" can be cast to type "rvalue reference to cv2
// T2" if "cv2 T2" is reference-compatible with "cv1 T1".
- tcr = TryLValueToRValueCast(Self, SrcExpr, DestType, Kind, BasePath, msg);
+ tcr = TryLValueToRValueCast(Self, SrcExpr, DestType, CStyle, Kind, BasePath,
+ msg);
if (tcr != TC_NotApplicable)
return tcr;
@@ -695,7 +697,8 @@ static TryCastResult TryStaticCast(Sema &Self, Expr *&SrcExpr,
/// Tests whether a conversion according to N2844 is valid.
TryCastResult
TryLValueToRValueCast(Sema &Self, Expr *SrcExpr, QualType DestType,
- CastKind &Kind, CXXCastPath &BasePath, unsigned &msg) {
+ bool CStyle, CastKind &Kind, CXXCastPath &BasePath,
+ unsigned &msg) {
// C++0x [expr.static.cast]p3:
// A glvalue of type "cv1 T1" can be cast to type "rvalue reference to
// cv2 T2" if "cv2 T2" is reference-compatible with "cv1 T1".
@@ -711,8 +714,15 @@ TryLValueToRValueCast(Sema &Self, Expr *SrcExpr, QualType DestType,
// FIXME: Should allow casting away constness if CStyle.
bool DerivedToBase;
bool ObjCConversion;
+ QualType FromType = SrcExpr->getType();
+ QualType ToType = R->getPointeeType();
+ if (CStyle) {
+ FromType = FromType.getUnqualifiedType();
+ ToType = ToType.getUnqualifiedType();
+ }
+
if (Self.CompareReferenceRelationship(SrcExpr->getLocStart(),
- R->getPointeeType(), SrcExpr->getType(),
+ ToType, FromType,
DerivedToBase, ObjCConversion) <
Sema::Ref_Compatible_With_Added_Qualification) {
msg = diag::err_bad_lvalue_to_rvalue_cast;