aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-04-16 19:30:02 +0000
committerDouglas Gregor <dgregor@apple.com>2010-04-16 19:30:02 +0000
commitf0e43e5c4634870b8ac7bf65d5ffa5f292d4c8a5 (patch)
tree7457722861d80cfc109b40a3cc3c1d6c81de0774
parent0ade808e0ac411baa2dbc1f76ad352b9b6d6d3f8 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101526 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaCXXCast.cpp32
-rw-r--r--lib/Sema/SemaInit.cpp13
2 files changed, 23 insertions, 22 deletions
diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp
index a40bb62b17..716e51b7dd 100644
--- a/lib/Sema/SemaCXXCast.cpp
+++ b/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/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index b66c9805c3..edff4a5396 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/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;