@@ -221,7 +221,7 @@ static void DiagnoseCastQual(Sema &Self, const ExprResult &SrcExpr,
221221// %2: Destination Type
222222static TryCastResult TryLValueToRValueCast (Sema &Self, Expr *SrcExpr,
223223 QualType DestType, bool CStyle,
224- CastKind &Kind,
224+ SourceRange OpRange, CastKind &Kind,
225225 CXXCastPath &BasePath,
226226 unsigned &msg);
227227static TryCastResult TryStaticReferenceDowncast (Sema &Self, Expr *SrcExpr,
@@ -1357,8 +1357,8 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr,
13571357 // C++11 [expr.static.cast]p3:
13581358 // A glvalue of type "cv1 T1" can be cast to type "rvalue reference to cv2
13591359 // T2" if "cv2 T2" is reference-compatible with "cv1 T1".
1360- tcr = TryLValueToRValueCast (Self, SrcExpr.get (), DestType, CStyle, Kind ,
1361- BasePath, msg);
1360+ tcr = TryLValueToRValueCast (Self, SrcExpr.get (), DestType, CStyle, OpRange ,
1361+ Kind, BasePath, msg);
13621362 if (tcr != TC_NotApplicable)
13631363 return tcr;
13641364
@@ -1534,8 +1534,8 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr,
15341534// / Tests whether a conversion according to N2844 is valid.
15351535TryCastResult TryLValueToRValueCast (Sema &Self, Expr *SrcExpr,
15361536 QualType DestType, bool CStyle,
1537- CastKind &Kind, CXXCastPath &BasePath ,
1538- unsigned &msg) {
1537+ SourceRange OpRange, CastKind &Kind ,
1538+ CXXCastPath &BasePath, unsigned &msg) {
15391539 // C++11 [expr.static.cast]p3:
15401540 // A glvalue of type "cv1 T1" can be cast to type "rvalue reference to
15411541 // cv2 T2" if "cv2 T2" is reference-compatible with "cv1 T1".
@@ -1548,7 +1548,6 @@ TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr,
15481548
15491549 // Because we try the reference downcast before this function, from now on
15501550 // this is the only cast possibility, so we issue an error if we fail now.
1551- // FIXME: Should allow casting away constness if CStyle.
15521551 QualType FromType = SrcExpr->getType ();
15531552 QualType ToType = R->getPointeeType ();
15541553 if (CStyle) {
@@ -1572,13 +1571,12 @@ TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr,
15721571
15731572 if (RefConv & Sema::ReferenceConversions::DerivedToBase) {
15741573 Kind = CK_DerivedToBase;
1575- CXXBasePaths Paths (/* FindAmbiguities=*/ true , /* RecordPaths=*/ true ,
1576- /* DetectVirtual=*/ true );
1577- if (!Self.IsDerivedFrom (SrcExpr->getBeginLoc (), SrcExpr->getType (),
1578- R->getPointeeType (), Paths))
1579- return TC_NotApplicable;
1580-
1581- Self.BuildBasePathArray (Paths, BasePath);
1574+ if (Self.CheckDerivedToBaseConversion (FromType, ToType,
1575+ SrcExpr->getBeginLoc (), OpRange,
1576+ &BasePath, CStyle)) {
1577+ msg = 0 ;
1578+ return TC_Failed;
1579+ }
15821580 } else
15831581 Kind = CK_NoOp;
15841582
0 commit comments