diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-11-18 18:26:29 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-11-18 18:26:29 +0000 |
commit | cc5306ac8a39cdd5e7f83e597cba911e97c4a595 (patch) | |
tree | 79e3bbae91eebf51db844dcbf22ead92f7e997fe /lib/Sema/SemaOverload.cpp | |
parent | 76d69bb7f984c390f90504a06dfc7485387ffdd7 (diff) |
Improve on diagnosing type mismatches because of
lack of viable convesion functions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89216 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaOverload.cpp')
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index adcd977e62..c9c16aafc4 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -1545,18 +1545,23 @@ Sema::OverloadingResult Sema::IsUserDefinedConversion( } bool -Sema::DiagnoseAmbiguousUserDefinedConversion(Expr *From, QualType ToType) { +Sema::DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType) { ImplicitConversionSequence ICS; OverloadCandidateSet CandidateSet; OverloadingResult OvResult = IsUserDefinedConversion(From, ToType, ICS.UserDefined, CandidateSet, true, false, false); - if (OvResult != OR_Ambiguous) + if (OvResult == OR_Ambiguous) + Diag(From->getSourceRange().getBegin(), + diag::err_typecheck_ambiguous_condition) + << From->getType() << ToType << From->getSourceRange(); + else if (OvResult == OR_No_Viable_Function && !CandidateSet.empty()) + Diag(From->getSourceRange().getBegin(), + diag::err_typecheck_nonviable_condition) + << From->getType() << ToType << From->getSourceRange(); + else return false; - Diag(From->getSourceRange().getBegin(), - diag::err_typecheck_ambiguous_condition) - << From->getType() << ToType << From->getSourceRange(); - PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false); + PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false); return true; } @@ -2072,7 +2077,7 @@ bool Sema::PerformCopyInitialization(Expr *&From, QualType ToType, if (!PerformImplicitConversion(From, ToType, Flavor, /*AllowExplicit=*/false, Elidable)) return false; - if (!DiagnoseAmbiguousUserDefinedConversion(From, ToType)) + if (!DiagnoseMultipleUserDefinedConversion(From, ToType)) return Diag(From->getSourceRange().getBegin(), diag::err_typecheck_convert_incompatible) << ToType << From->getType() << Flavor << From->getSourceRange(); @@ -2192,7 +2197,7 @@ bool Sema::PerformContextuallyConvertToBool(Expr *&From) { if (!PerformImplicitConversion(From, Context.BoolTy, ICS, "converting")) return false; - if (!DiagnoseAmbiguousUserDefinedConversion(From, Context.BoolTy)) + if (!DiagnoseMultipleUserDefinedConversion(From, Context.BoolTy)) return Diag(From->getSourceRange().getBegin(), diag::err_typecheck_bool_condition) << From->getType() << From->getSourceRange(); |