diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-04-16 19:30:02 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-04-16 19:30:02 +0000 |
commit | 5c8ffab9fb1060e363e0cc02caeafce53d9e660f (patch) | |
tree | ad43c2d31c167c731d669fbdeb450d144f4eadcf | |
parent | 7fc8123b374aeb31dd174b4ec894e03095791a75 (diff) | |
download | bcm5719-llvm-5c8ffab9fb1060e363e0cc02caeafce53d9e660f.tar.gz bcm5719-llvm-5c8ffab9fb1060e363e0cc02caeafce53d9e660f.zip |
Switch the checking of implicit casts for static_cast, C-style, and
functional casts over to InitializationSequence, eliminating a caller
of Sema::TryImplicitConversion. We also get access and ambiguity
checking "for free".
More cleanups to come in this routine.
llvm-svn: 101526
-rw-r--r-- | clang/lib/Sema/SemaCXXCast.cpp | 32 | ||||
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 13 |
2 files changed, 23 insertions, 22 deletions
diff --git a/clang/lib/Sema/SemaCXXCast.cpp b/clang/lib/Sema/SemaCXXCast.cpp index a40bb62b179..716e51b7dda 100644 --- a/clang/lib/Sema/SemaCXXCast.cpp +++ b/clang/lib/Sema/SemaCXXCast.cpp @@ -953,26 +953,24 @@ TryStaticImplicitCast(Sema &Self, Expr *&SrcExpr, QualType DestType, return TC_NotApplicable; } - // FIXME: To get a proper error from invalid conversions here, we need to - // reimplement more of this. - // FIXME: This does not actually perform the conversion, and thus does not - // check for ambiguity or access. - ImplicitConversionSequence ICS = - Self.TryImplicitConversion(SrcExpr, DestType, - /*SuppressUserConversions=*/false, - /*AllowExplicit=*/true, - /*InOverloadResolution=*/false, - /*one of user provided casts*/true); - - if (ICS.isBad()) + InitializedEntity Entity = InitializedEntity::InitializeTemporary(DestType); + InitializationKind InitKind + = InitializationKind::CreateCast(/*FIXME:*/OpRange, CStyle); + InitializationSequence InitSeq(Self, Entity, InitKind, &SrcExpr, 1); + if (InitSeq.getKind() == InitializationSequence::FailedSequence) return TC_NotApplicable; - // The conversion is possible, so commit to it. + Sema::OwningExprResult Result + = InitSeq.Perform(Self, Entity, InitKind, + Action::MultiExprArg(Self, (void **)&SrcExpr, 1)); Kind = CastExpr::CK_NoOp; - msg = 0; - return Self.PerformImplicitConversion(SrcExpr, DestType, ICS, Sema::AA_Casting, - /*IgnoreBaseAccess*/CStyle) ? - TC_Failed : TC_Success; + if (Result.isInvalid()) { + msg = 0; + return TC_Failed; + } + + SrcExpr = Result.takeAs<Expr>(); + return TC_Success; } /// TryConstCast - See if a const_cast from source to destination is allowed, diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index b66c9805c37..edff4a53964 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -3486,15 +3486,18 @@ InitializationSequence::Perform(Sema &S, CurInit = S.Owned(CurInitExpr); break; - case SK_ConversionSequence: - if (S.PerformImplicitConversion(CurInitExpr, Step->Type, Sema::AA_Converting, - false, *Step->ICS)) + case SK_ConversionSequence: { + bool IgnoreBaseAccess = Kind.isCStyleOrFunctionalCast(); + + if (S.PerformImplicitConversion(CurInitExpr, Step->Type, *Step->ICS, + Sema::AA_Converting, IgnoreBaseAccess)) return S.ExprError(); CurInit.release(); - CurInit = S.Owned(CurInitExpr); + CurInit = S.Owned(CurInitExpr); break; - + } + case SK_ListInitialization: { InitListExpr *InitList = cast<InitListExpr>(CurInitExpr); QualType Ty = Step->Type; |