diff options
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/Sema.cpp | 58 | ||||
-rw-r--r-- | lib/Sema/SemaCast.cpp | 78 | ||||
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 132 | ||||
-rw-r--r-- | lib/Sema/SemaInit.cpp | 2 |
4 files changed, 91 insertions, 179 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 0ce816b8dc..fe393dd2fe 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -234,16 +234,13 @@ void Sema::PrintStats() const { AnalysisWarnings.PrintStats(); } -/// CastExprToType - If Expr is not of type 'Type', insert a cast of the -/// specified kind. -/// Redundant implicit casts are merged together. -/// Pay attention: if CCK != CCK_ImplicitConversion, -/// users of this function must fill -/// SourceTypeInfos and SourceLocations later -ExprResult Sema::CastExprToType(Expr *E, QualType Ty, - CastKind Kind, ExprValueKind VK, - const CXXCastPath *BasePath, - CheckedConversionKind CCK) { +/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. +/// If there is already an implicit cast, merge into the existing one. +/// The result is of the given category. +ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty, + CastKind Kind, ExprValueKind VK, + const CXXCastPath *BasePath, + CheckedConversionKind CCK) { #ifndef NDEBUG if (VK == VK_RValue && !E->isRValue()) { switch (Kind) { @@ -279,41 +276,16 @@ ExprResult Sema::CastExprToType(Expr *E, QualType Ty, MarkVTableUsed(E->getLocStart(), cast<CXXRecordDecl>(RecordTy->getDecl())); } - - switch(CCK) { - default: - llvm_unreachable("Unexpected CheckedConversionKind"); - case CCK_ImplicitConversion: - if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(E)) { - if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) { - ImpCast->setType(Ty); - ImpCast->setValueKind(VK); - return Owned(E); - } - } - return Owned(ImplicitCastExpr::Create(Context, Ty, Kind, E, BasePath, VK)); - case CCK_CStyleCast: - return Owned(CStyleCastExpr::Create(Context, Ty, VK, Kind, E, BasePath, - 0, SourceLocation(), SourceLocation())); - case CCK_FunctionalCast: - return Owned(CXXFunctionalCastExpr::Create(Context, Ty, VK, 0, - SourceLocation(), Kind, E, - BasePath, SourceLocation())); - case CCK_StaticCast: - return Owned(CXXStaticCastExpr::Create(Context, Ty, VK, Kind, E, BasePath, - 0, SourceLocation(), - SourceLocation())); + + if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(E)) { + if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) { + ImpCast->setType(Ty); + ImpCast->setValueKind(VK); + return Owned(E); + } } - -} -/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. -/// If there is already an implicit cast, merge into the existing one. -/// The result is of the given category. -ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty, - CastKind Kind, ExprValueKind VK, - const CXXCastPath *BasePath) { - return CastExprToType(E, Ty, Kind, VK, BasePath, CCK_ImplicitConversion); + return Owned(ImplicitCastExpr::Create(Context, Ty, Kind, E, BasePath, VK)); } /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding diff --git a/lib/Sema/SemaCast.cpp b/lib/Sema/SemaCast.cpp index 586d3cbae6..0250b3e380 100644 --- a/lib/Sema/SemaCast.cpp +++ b/lib/Sema/SemaCast.cpp @@ -75,9 +75,9 @@ namespace { // Top-level semantics-checking routines. void CheckConstCast(); void CheckReinterpretCast(); - void CheckStaticCast(bool &CastNodesCreated); + void CheckStaticCast(); void CheckDynamicCast(); - void CheckCXXCStyleCast(bool FunctionalCast, bool &CastNodesCreated); + void CheckCXXCStyleCast(bool FunctionalCast); void CheckCStyleCast(); /// Complete an apparently-successful cast operation that yields @@ -283,28 +283,12 @@ Sema::BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, Parens.getEnd())); } case tok::kw_static_cast: { - bool CastNodesCreated = false; if (!TypeDependent) { - Op.CheckStaticCast(CastNodesCreated); + Op.CheckStaticCast(); if (Op.SrcExpr.isInvalid()) return ExprError(); } - // CheckStaticCast _may_ have already created the cast node. Let's check - if (CastNodesCreated) { - if (CXXStaticCastExpr *Cast = - dyn_cast<CXXStaticCastExpr>(Op.SrcExpr.get())) { - assert(!Cast->getTypeInfoAsWritten() && - "The explicit cast node created by CheckStaticCast " - "has source type infos!"); - - Cast->setTypeInfoAsWritten(DestTInfo); - Cast->setOperatorLoc(OpLoc); - Cast->setRParenLoc(Parens.getEnd()); - - return Op.complete(Cast); - } - } return Op.complete(CXXStaticCastExpr::Create(Context, Op.ResultType, Op.ValueKind, Op.Kind, Op.SrcExpr.take(), &Op.BasePath, DestTInfo, @@ -343,7 +327,7 @@ static bool tryDiagnoseOverloadedCast(Sema &S, CastType CT, = (CT == CT_CStyle)? InitializationKind::CreateCStyleCast(range.getBegin(), range) : (CT == CT_Functional)? InitializationKind::CreateFunctionalCast(range) - : InitializationKind::CreateStaticCast(/*type range?*/ range); + : InitializationKind::CreateCast(/*type range?*/ range); InitializationSequence sequence(S, entity, initKind, &src, 1); assert(sequence.Failed() && "initialization succeeded on second try?"); @@ -730,7 +714,7 @@ void CastOperation::CheckReinterpretCast() { /// CheckStaticCast - Check that a static_cast\<DestType\>(SrcExpr) is valid. /// Refer to C++ 5.2.9 for details. Static casts are mostly used for making /// implicit conversions explicit and getting rid of data loss warnings. -void CastOperation::CheckStaticCast(bool &CastNodesCreated) { +void CastOperation::CheckStaticCast() { if (isPlaceholder()) { checkNonOverloadPlaceholders(); if (SrcExpr.isInvalid()) @@ -763,10 +747,9 @@ void CastOperation::CheckStaticCast(bool &CastNodesCreated) { return; } - Expr *SrcExprOrig = SrcExpr.get(); unsigned msg = diag::err_bad_cxx_cast_generic; TryCastResult tcr - = TryStaticCast(Self, SrcExpr, DestType, Sema::CCK_StaticCast, OpRange, msg, + = TryStaticCast(Self, SrcExpr, DestType, Sema::CCK_OtherCast, OpRange, msg, Kind, BasePath); if (tcr != TC_Success && msg != 0) { if (SrcExpr.isInvalid()) @@ -784,12 +767,10 @@ void CastOperation::CheckStaticCast(bool &CastNodesCreated) { if (Kind == CK_BitCast) checkCastAlign(); if (Self.getLangOptions().ObjCAutoRefCount) - checkObjCARCConversion(Sema::CCK_StaticCast); + checkObjCARCConversion(Sema::CCK_OtherCast); } else if (Kind == CK_BitCast) { checkCastAlign(); } - - CastNodesCreated = (SrcExpr.get() != SrcExprOrig); } /// TryStaticCast - Check if a static cast can be performed, and do so if @@ -1327,7 +1308,7 @@ TryStaticImplicitCast(Sema &Self, ExprResult &SrcExpr, QualType DestType, ? InitializationKind::CreateCStyleCast(OpRange.getBegin(), OpRange) : (CCK == Sema::CCK_FunctionalCast) ? InitializationKind::CreateFunctionalCast(OpRange) - : InitializationKind::CreateStaticCast(OpRange); + : InitializationKind::CreateCast(OpRange); Expr *SrcExprRaw = SrcExpr.get(); InitializationSequence InitSeq(Self, Entity, InitKind, &SrcExprRaw, 1); @@ -1761,9 +1742,7 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr, return TC_Success; } -void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle, - bool &CastNodesCreated) { - CastNodesCreated = false; +void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle) { // Handle placeholders. if (isPlaceholder()) { // C-style casts can resolve __unknown_any types. @@ -1844,7 +1823,6 @@ void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle, = FunctionalStyle? Sema::CCK_FunctionalCast : Sema::CCK_CStyleCast; if (tcr == TC_NotApplicable) { - Expr *SrcExprOrig = SrcExpr.get(); // ... or if that is not possible, a static_cast, ignoring const, ... tcr = TryStaticCast(Self, SrcExpr, DestType, CCK, OpRange, msg, Kind, BasePath); @@ -1858,8 +1836,6 @@ void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle, if (SrcExpr.isInvalid()) return; } - - CastNodesCreated = (SrcExpr.get() != SrcExprOrig); } if (Self.getLangOptions().ObjCAutoRefCount && tcr == TC_Success) @@ -2077,9 +2053,8 @@ ExprResult Sema::BuildCStyleCastExpr(SourceLocation LPLoc, Op.DestRange = CastTypeInfo->getTypeLoc().getSourceRange(); Op.OpRange = SourceRange(LPLoc, CastExpr->getLocEnd()); - bool CastNodesCreated = false; if (getLangOptions().CPlusPlus) { - Op.CheckCXXCStyleCast(/*FunctionalStyle=*/ false, CastNodesCreated); + Op.CheckCXXCStyleCast(/*FunctionalStyle=*/ false); } else { Op.CheckCStyleCast(); } @@ -2087,20 +2062,6 @@ ExprResult Sema::BuildCStyleCastExpr(SourceLocation LPLoc, if (Op.SrcExpr.isInvalid()) return ExprError(); - // CheckCXXCStyleCast _may_ have already created the CStyleCastExpr - // node. Let's check. - if (CastNodesCreated) { - if (CStyleCastExpr *Cast = dyn_cast<CStyleCastExpr>(Op.SrcExpr.get())){ - assert(!Cast->getTypeInfoAsWritten() && - "The explicit cast node created by CheckStaticCast " - "has source type infos!"); - Cast->setTypeInfoAsWritten(CastTypeInfo); - Cast->setLParenLoc(LPLoc); - Cast->setRParenLoc(RPLoc); - return Op.complete(Cast); - } - } - return Op.complete(CStyleCastExpr::Create(Context, Op.ResultType, Op.ValueKind, Op.Kind, Op.SrcExpr.take(), &Op.BasePath, CastTypeInfo, LPLoc, RPLoc)); @@ -2114,28 +2075,11 @@ ExprResult Sema::BuildCXXFunctionalCastExpr(TypeSourceInfo *CastTypeInfo, Op.DestRange = CastTypeInfo->getTypeLoc().getSourceRange(); Op.OpRange = SourceRange(Op.DestRange.getBegin(), CastExpr->getLocEnd()); - bool CastNodesCreated = false; - Op.CheckCXXCStyleCast(/*FunctionalStyle=*/ true, CastNodesCreated); + Op.CheckCXXCStyleCast(/*FunctionalStyle=*/ true); if (Op.SrcExpr.isInvalid()) return ExprError(); - // CheckCXXCStyleCast _may_ have already created the CXXFunctionalCastExpr - // node. Let's check. - if (CastNodesCreated) { - if (CXXFunctionalCastExpr *Cast = - dyn_cast<CXXFunctionalCastExpr>(Op.SrcExpr.get())){ - assert(!Cast->getTypeInfoAsWritten() && - "The explicit cast node created by CheckStaticCast " - "has source type infos!"); - Cast->setTypeInfoAsWritten(CastTypeInfo); - Cast->setTypeBeginLoc(Op.DestRange.getBegin()); - Cast->setRParenLoc(RPLoc); - return Op.complete(Cast); - } - } - return Op.complete(CXXFunctionalCastExpr::Create(Context, Op.ResultType, Op.ValueKind, CastTypeInfo, Op.DestRange.getBegin(), Op.Kind, Op.SrcExpr.take(), &Op.BasePath, RPLoc)); } - diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index ac49b4966a..973e92d214 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -2125,8 +2125,8 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType, CheckedConversionKind CCK) { switch (ICS.getKind()) { case ImplicitConversionSequence::StandardConversion: { - ExprResult Res = PerformConversion(From, ToType, ICS.Standard, - Action, CCK); + ExprResult Res = PerformImplicitConversion(From, ToType, ICS.Standard, + Action, CCK); if (Res.isInvalid()) return ExprError(); From = Res.take(); @@ -2160,8 +2160,9 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType, // Watch out for elipsis conversion. if (!ICS.UserDefined.EllipsisConversion) { ExprResult Res = - PerformConversion(From, BeforeToType, - ICS.UserDefined.Before, AA_Converting, CCK); + PerformImplicitConversion(From, BeforeToType, + ICS.UserDefined.Before, AA_Converting, + CCK); if (Res.isInvalid()) return ExprError(); From = Res.take(); @@ -2181,8 +2182,8 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType, From = CastArg.take(); - return PerformConversion(From, ToType, ICS.UserDefined.After, - AA_Converting, CCK); + return PerformImplicitConversion(From, ToType, ICS.UserDefined.After, + AA_Converting, CCK); } case ImplicitConversionSequence::AmbiguousConversion: @@ -2202,13 +2203,13 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType, return Owned(From); } -/// PerformConversion - Perform a conversion of the +/// PerformImplicitConversion - Perform an implicit conversion of the /// expression From to the type ToType by following the standard /// conversion sequence SCS. Returns the converted /// expression. Flavor is the context in which we're performing this /// conversion, for use in error messages. ExprResult -Sema::PerformConversion(Expr *From, QualType ToType, +Sema::PerformImplicitConversion(Expr *From, QualType ToType, const StandardConversionSequence& SCS, AssignmentAction Action, CheckedConversionKind CCK) { @@ -2262,7 +2263,7 @@ Sema::PerformConversion(Expr *From, QualType ToType, FromType = From->getType(); } - // Perform the first conversion step. + // Perform the first implicit conversion. switch (SCS.First) { case ICK_Identity: // Nothing to do. @@ -2277,21 +2278,21 @@ Sema::PerformConversion(Expr *From, QualType ToType, case ICK_Array_To_Pointer: FromType = Context.getArrayDecayedType(FromType); - From = CastExprToType(From, FromType, CK_ArrayToPointerDecay, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, FromType, CK_ArrayToPointerDecay, + VK_RValue, /*BasePath=*/0, CCK).take(); break; case ICK_Function_To_Pointer: FromType = Context.getPointerType(FromType); - From = CastExprToType(From, FromType, CK_FunctionToPointerDecay, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, FromType, CK_FunctionToPointerDecay, + VK_RValue, /*BasePath=*/0, CCK).take(); break; default: llvm_unreachable("Improper first standard conversion"); } - // Perform the second conversion step + // Perform the second implicit conversion switch (SCS.Second) { case ICK_Identity: // If both sides are functions (or pointers/references to them), there could @@ -2307,20 +2308,20 @@ Sema::PerformConversion(Expr *From, QualType ToType, if (CheckExceptionSpecCompatibility(From, ToType)) return ExprError(); - From = CastExprToType(From, ToType, CK_NoOp, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ToType, CK_NoOp, + VK_RValue, /*BasePath=*/0, CCK).take(); break; case ICK_Integral_Promotion: case ICK_Integral_Conversion: - From = CastExprToType(From, ToType, CK_IntegralCast, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ToType, CK_IntegralCast, + VK_RValue, /*BasePath=*/0, CCK).take(); break; case ICK_Floating_Promotion: case ICK_Floating_Conversion: - From = CastExprToType(From, ToType, CK_FloatingCast, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ToType, CK_FloatingCast, + VK_RValue, /*BasePath=*/0, CCK).take(); break; case ICK_Complex_Promotion: @@ -2338,23 +2339,23 @@ Sema::PerformConversion(Expr *From, QualType ToType, } else { CK = CK_IntegralComplexCast; } - From = CastExprToType(From, ToType, CK, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ToType, CK, + VK_RValue, /*BasePath=*/0, CCK).take(); break; } case ICK_Floating_Integral: if (ToType->isRealFloatingType()) - From = CastExprToType(From, ToType, CK_IntegralToFloating, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ToType, CK_IntegralToFloating, + VK_RValue, /*BasePath=*/0, CCK).take(); else - From = CastExprToType(From, ToType, CK_FloatingToIntegral, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ToType, CK_FloatingToIntegral, + VK_RValue, /*BasePath=*/0, CCK).take(); break; case ICK_Compatible_Conversion: - From = CastExprToType(From, ToType, CK_NoOp, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ToType, CK_NoOp, + VK_RValue, /*BasePath=*/0, CCK).take(); break; case ICK_Writeback_Conversion: @@ -2402,7 +2403,8 @@ Sema::PerformConversion(Expr *From, QualType ToType, From = E.take(); } - From = CastExprToType(From, ToType, Kind, VK_RValue, &BasePath, CCK).take(); + From = ImpCastExprToType(From, ToType, Kind, VK_RValue, &BasePath, CCK) + .take(); break; } @@ -2413,7 +2415,8 @@ Sema::PerformConversion(Expr *From, QualType ToType, return ExprError(); if (CheckExceptionSpecCompatibility(From, ToType)) return ExprError(); - From = CastExprToType(From, ToType, Kind, VK_RValue, &BasePath, CCK).take(); + From = ImpCastExprToType(From, ToType, Kind, VK_RValue, &BasePath, CCK) + .take(); break; } @@ -2424,9 +2427,9 @@ Sema::PerformConversion(Expr *From, QualType ToType, FromType = Context.FloatTy; } - From = CastExprToType(From, Context.BoolTy, - ScalarTypeToBooleanCastKind(FromType), - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, Context.BoolTy, + ScalarTypeToBooleanCastKind(FromType), + VK_RValue, /*BasePath=*/0, CCK).take(); break; case ICK_Derived_To_Base: { @@ -2439,20 +2442,20 @@ Sema::PerformConversion(Expr *From, QualType ToType, CStyle)) return ExprError(); - From = CastExprToType(From, ToType.getNonReferenceType(), - CK_DerivedToBase, From->getValueKind(), - &BasePath, CCK).take(); + From = ImpCastExprToType(From, ToType.getNonReferenceType(), + CK_DerivedToBase, From->getValueKind(), + &BasePath, CCK).take(); break; } case ICK_Vector_Conversion: - From = CastExprToType(From, ToType, CK_BitCast, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ToType, CK_BitCast, + VK_RValue, /*BasePath=*/0, CCK).take(); break; case ICK_Vector_Splat: - From = CastExprToType(From, ToType, CK_VectorSplat, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ToType, CK_VectorSplat, + VK_RValue, /*BasePath=*/0, CCK).take(); break; case ICK_Complex_Real: @@ -2465,22 +2468,17 @@ Sema::PerformConversion(Expr *From, QualType ToType, if (Context.hasSameUnqualifiedType(ElType, From->getType())) { // do nothing } else if (From->getType()->isRealFloatingType()) { - From = CastExprToType(From, ElType, - isFloatingComplex ? CK_FloatingCast - : CK_FloatingToIntegral, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ElType, + isFloatingComplex ? CK_FloatingCast : CK_FloatingToIntegral).take(); } else { assert(From->getType()->isIntegerType()); - From = CastExprToType(From, ElType, - isFloatingComplex ? CK_IntegralToFloating - : CK_IntegralCast, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ElType, + isFloatingComplex ? CK_IntegralToFloating : CK_IntegralCast).take(); } // y -> _Complex y - From = CastExprToType(From, ToType, - isFloatingComplex ? CK_FloatingRealToComplex - : CK_IntegralRealToComplex, - VK_RValue, /*BasePath=*/ 0, CCK).take(); + From = ImpCastExprToType(From, ToType, + isFloatingComplex ? CK_FloatingRealToComplex + : CK_IntegralRealToComplex).take(); // Case 2. _Complex x -> y } else { @@ -2491,32 +2489,30 @@ Sema::PerformConversion(Expr *From, QualType ToType, bool isFloatingComplex = ElType->isRealFloatingType(); // _Complex x -> x - From = CastExprToType(From, ElType, - isFloatingComplex ? CK_FloatingComplexToReal - : CK_IntegralComplexToReal, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ElType, + isFloatingComplex ? CK_FloatingComplexToReal + : CK_IntegralComplexToReal, + VK_RValue, /*BasePath=*/0, CCK).take(); // x -> y if (Context.hasSameUnqualifiedType(ElType, ToType)) { // do nothing } else if (ToType->isRealFloatingType()) { - From = CastExprToType(From, ToType, - isFloatingComplex ? CK_FloatingCast - : CK_IntegralToFloating, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ToType, + isFloatingComplex ? CK_FloatingCast : CK_IntegralToFloating, + VK_RValue, /*BasePath=*/0, CCK).take(); } else { assert(ToType->isIntegerType()); - From = CastExprToType(From, ToType, - isFloatingComplex ? CK_FloatingToIntegral - : CK_IntegralCast, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ToType, + isFloatingComplex ? CK_FloatingToIntegral : CK_IntegralCast, + VK_RValue, /*BasePath=*/0, CCK).take(); } } break; case ICK_Block_Pointer_Conversion: { - From = CastExprToType(From, ToType.getUnqualifiedType(), CK_BitCast, - VK_RValue, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ToType.getUnqualifiedType(), CK_BitCast, + VK_RValue, /*BasePath=*/0, CCK).take(); break; } @@ -2551,8 +2547,8 @@ Sema::PerformConversion(Expr *From, QualType ToType, // target type isn't a reference. ExprValueKind VK = ToType->isReferenceType() ? From->getValueKind() : VK_RValue; - From = CastExprToType(From, ToType.getNonLValueExprType(Context), - CK_NoOp, VK, /*BasePath=*/0, CCK).take(); + From = ImpCastExprToType(From, ToType.getNonLValueExprType(Context), + CK_NoOp, VK, /*BasePath=*/0, CCK).take(); if (SCS.DeprecatedStringLiteralToCharPtr && !getLangOptions().WritableStrings) diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 3c89dd5811..a95a257131 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -4863,7 +4863,7 @@ InitializationSequence::Perform(Sema &S, Sema::CheckedConversionKind CCK = Kind.isCStyleCast()? Sema::CCK_CStyleCast : Kind.isFunctionalCast()? Sema::CCK_FunctionalCast - : Kind.isStaticCast()? Sema::CCK_StaticCast + : Kind.isExplicitCast()? Sema::CCK_OtherCast : Sema::CCK_ImplicitConversion; ExprResult CurInitExprRes = S.PerformImplicitConversion(CurInit.get(), Step->Type, *Step->ICS, |