diff options
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/Sema.h | 12 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 5 | ||||
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 11 | ||||
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 18 |
4 files changed, 31 insertions, 15 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index a5a0723256..8a8e9456ca 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -721,13 +721,17 @@ public: bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old); /// C++ Overloading. + enum OverloadResolutionFlags { + ORF_None = 0x0, + ORF_SuppressUserConversions = 0x1, + ORF_AllowExplicit = 0x2, + ORF_ForceRValue = 0x4 + }; + bool IsOverload(FunctionDecl *New, Decl* OldD, OverloadedFunctionDecl::function_iterator &MatchedDecl); ImplicitConversionSequence - TryImplicitConversion(Expr* From, QualType ToType, - bool SuppressUserConversions = false, - bool AllowExplicit = false, - bool ForceRValue = false); + TryImplicitConversion(Expr* From, QualType ToType, unsigned Flags = ORF_None); bool IsStandardConversion(Expr *From, QualType ToType, StandardConversionSequence& SCS); bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index c5eda94b6a..be45a2d56d 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -3144,7 +3144,10 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, // the argument expression. Any difference in top-level // cv-qualification is subsumed by the initialization itself // and does not constitute a conversion. - *ICS = TryImplicitConversion(Init, T1, SuppressUserConversions); + *ICS = TryImplicitConversion(Init, T1, + SuppressUserConversions ? + ORF_SuppressUserConversions : + ORF_None); // Of course, that's still a reference binding. if (ICS->ConversionKind == ImplicitConversionSequence::StandardConversion) { ICS->Standard.ReferenceBinding = true; diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 85924948da..1d05008cbe 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -881,14 +881,19 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, const char *Flavor, bool AllowExplicit, bool Elidable) { + unsigned Flags = ORF_None; + if (AllowExplicit) + Flags |= ORF_AllowExplicit; + ImplicitConversionSequence ICS; ICS.ConversionKind = ImplicitConversionSequence::BadConversion; if (Elidable && getLangOptions().CPlusPlus0x) { - ICS = TryImplicitConversion(From, ToType, /*SuppressUserConversions*/false, - AllowExplicit, /*ForceRValue*/true); + Flags |= ORF_ForceRValue; + + ICS = TryImplicitConversion(From, ToType, Flags); } if (ICS.ConversionKind == ImplicitConversionSequence::BadConversion) { - ICS = TryImplicitConversion(From, ToType, false, AllowExplicit); + ICS = TryImplicitConversion(From, ToType, Flags); } return PerformImplicitConversion(From, ToType, ICS, Flavor); } diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index dde5c28723..2c8c731797 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -408,10 +408,11 @@ Sema::IsOverload(FunctionDecl *New, Decl* OldD, /// If @p ForceRValue, then overloading is performed as if From was an rvalue, /// no matter its actual lvalueness. ImplicitConversionSequence -Sema::TryImplicitConversion(Expr* From, QualType ToType, - bool SuppressUserConversions, - bool AllowExplicit, bool ForceRValue) -{ +Sema::TryImplicitConversion(Expr* From, QualType ToType, unsigned Flags) { + bool SuppressUserConversions = Flags & ORF_SuppressUserConversions; + bool AllowExplicit = Flags & ORF_AllowExplicit; + bool ForceRValue = Flags & ORF_ForceRValue; + ImplicitConversionSequence ICS; if (IsStandardConversion(From, ToType, ICS.Standard)) ICS.ConversionKind = ImplicitConversionSequence::StandardConversion; @@ -1929,8 +1930,11 @@ Sema::TryCopyInitialization(Expr *From, QualType ToType, /*AllowExplicit=*/false, ForceRValue); return ICS; } else { - return TryImplicitConversion(From, ToType, SuppressUserConversions, - ForceRValue); + unsigned Flags = ORF_None; + if (SuppressUserConversions) Flags |= ORF_SuppressUserConversions; + if (ForceRValue) Flags |= ORF_ForceRValue; + + return TryImplicitConversion(From, ToType, Flags); } } @@ -2064,7 +2068,7 @@ Sema::PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method) { /// TryContextuallyConvertToBool - Attempt to contextually convert the /// expression From to bool (C++0x [conv]p3). ImplicitConversionSequence Sema::TryContextuallyConvertToBool(Expr *From) { - return TryImplicitConversion(From, Context.BoolTy, false, true); + return TryImplicitConversion(From, Context.BoolTy, ORF_AllowExplicit); } /// PerformContextuallyConvertToBool - Perform a contextual conversion |