From c869e6070748b2532327ee5ad7fba4dc8925b359 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Tue, 25 Aug 2015 22:18:46 +0000 Subject: [PATCH] Clarify the error message when the reason the conversion is not viable is because the returned value does not match the function return type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245979 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 3 ++- lib/Sema/SemaInit.cpp | 1 + lib/Sema/SemaOverload.cpp | 2 +- .../dcl.spec/dcl.type/dcl.spec.auto/p3-generic-lambda-1y.cpp | 2 +- test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp | 2 +- test/SemaCXX/rval-references.cpp | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 08d3887203..819324609a 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -5792,7 +5792,8 @@ def err_typecheck_bool_condition : Error< def err_typecheck_ambiguous_condition : Error< "conversion %diff{from $ to $|between types}0,1 is ambiguous">; def err_typecheck_nonviable_condition : Error< - "no viable conversion%diff{ from $ to $|}0,1">; + "no viable conversion%select{%diff{ from $ to $|}1,2|" + "%diff{ from returned value of type $ to function return type $|}1,2}0">; def err_typecheck_nonviable_condition_incomplete : Error< "no viable conversion%diff{ from $ to incomplete type $|}0,1">; def err_typecheck_deleted_function : Error< diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 1b958ae782..de11666747 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -6946,6 +6946,7 @@ bool InitializationSequence::Diagnose(Sema &S, diag::err_typecheck_nonviable_condition_incomplete, Args[0]->getType(), Args[0]->getSourceRange())) S.Diag(Kind.getLocation(), diag::err_typecheck_nonviable_condition) + << (Entity.getKind() == InitializedEntity::EK_Result) << Args[0]->getType() << Args[0]->getSourceRange() << DestType.getNonReferenceType(); diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index ed986902fc..3906ba8e94 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -3212,7 +3212,7 @@ Sema::DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType) { diag::err_typecheck_nonviable_condition_incomplete, From->getType(), From->getSourceRange())) Diag(From->getLocStart(), diag::err_typecheck_nonviable_condition) - << From->getType() << From->getSourceRange() << ToType; + << false << From->getType() << From->getSourceRange() << ToType; } else return false; CandidateSet.NoteCandidates(*this, OCD_AllCandidates, From); diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3-generic-lambda-1y.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3-generic-lambda-1y.cpp index 65b085bcec..07bc884e7d 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3-generic-lambda-1y.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3-generic-lambda-1y.cpp @@ -49,7 +49,7 @@ int main() static double dfi(int i) { return i + 3.14; } static Local localfi(int) { return Local{}; } }; - auto l4 = [](auto (*fp)(int)) -> int { return fp(3); }; //expected-error{{no viable conversion from 'Local' to 'int'}} + auto l4 = [](auto (*fp)(int)) -> int { return fp(3); }; //expected-error{{no viable conversion from returned value of type 'Local' to function return type 'int'}} l4(&Local::ifi); l4(&Local::cfi); l4(&Local::dfi); diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp index c18bb7d192..e40761770d 100644 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp +++ b/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp @@ -38,7 +38,7 @@ template X captures(X, X); template int infer_result(T x, T y) { auto lambda = [=](bool b) { return x + y; }; - return lambda(true); // expected-error{{no viable conversion from 'X' to 'int'}} + return lambda(true); // expected-error{{no viable conversion from returned value of type 'X' to function return type 'int'}} } template int infer_result(int, int); diff --git a/test/SemaCXX/rval-references.cpp b/test/SemaCXX/rval-references.cpp index fc341e87f4..9c79ad7b0b 100644 --- a/test/SemaCXX/rval-references.cpp +++ b/test/SemaCXX/rval-references.cpp @@ -90,5 +90,5 @@ MoveOnly returningNonEligible() { else if (0) // Copy from reference can't be elided return r; // expected-error {{call to deleted constructor}} else // Construction from different type can't be elided - return i; // expected-error {{no viable conversion from 'int' to 'MoveOnly'}} + return i; // expected-error {{no viable conversion from returned value of type 'int' to function return type 'MoveOnly'}} } -- 2.40.0