From 866b2744ffe66294c8791cc8407b918f3bb81b2c Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 16 Oct 2009 23:25:02 +0000 Subject: [PATCH] Patch to clean up and improve visual display of builtin function ambiguity. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84289 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 4 ++-- lib/Sema/SemaOverload.cpp | 21 ++++++++++++------- .../ambiguous-builtin-unary-operator.cpp | 12 +++++------ test/SemaCXX/builtin-ptrtomember-ambig.cpp | 8 +++---- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index a38b8bc7d6..d1b0445989 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -785,9 +785,9 @@ def err_ovl_template_candidate : Note< def err_ovl_candidate_deleted : Note< "candidate function has been explicitly %select{made unavailable|deleted}0">; def err_ovl_builtin_binary_candidate : Note< - "built-in candidate operator %0 (%1, %2)">; + "built-in candidate %0">; def err_ovl_builtin_unary_candidate : Note< - "built-in candidate operator %0 (%1)">; + "built-in candidate %0">; def err_ovl_no_viable_function_in_init : Error< "no matching constructor for initialization of %0">; def err_ovl_ambiguous_init : Error<"call to constructor of %0 is ambiguous">; diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index a227dfba93..ecadcd904e 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -4148,13 +4148,20 @@ Sema::PrintOverloadCandidates(OverloadCandidateSet& CandidateSet, } else if (OnlyViable) { assert(Cand->Conversions.size() <= 2 && "builtin-binary-operator-not-binary"); - if (Cand->Conversions.size() == 1) - Diag(OpLoc, diag::err_ovl_builtin_unary_candidate) - << Opc << Cand->BuiltinTypes.ParamTypes[0]; - else - Diag(OpLoc, diag::err_ovl_builtin_binary_candidate) - << Opc << Cand->BuiltinTypes.ParamTypes[0] - << Cand->BuiltinTypes.ParamTypes[1]; + std::string TypeStr("operator"); + TypeStr += Opc; + TypeStr += "("; + TypeStr += Cand->BuiltinTypes.ParamTypes[0].getAsString(); + if (Cand->Conversions.size() == 1) { + TypeStr += ")"; + Diag(OpLoc, diag::err_ovl_builtin_unary_candidate) << TypeStr; + } + else { + TypeStr += ", "; + TypeStr += Cand->BuiltinTypes.ParamTypes[1].getAsString(); + TypeStr += ")"; + Diag(OpLoc, diag::err_ovl_builtin_binary_candidate) << TypeStr; + } } else if (!Cand->Viable && !Reported) { // Non-viability might be due to ambiguous user-defined conversions, diff --git a/test/SemaCXX/ambiguous-builtin-unary-operator.cpp b/test/SemaCXX/ambiguous-builtin-unary-operator.cpp index 0c9433ff6a..5affd19a2f 100644 --- a/test/SemaCXX/ambiguous-builtin-unary-operator.cpp +++ b/test/SemaCXX/ambiguous-builtin-unary-operator.cpp @@ -14,10 +14,10 @@ struct C : B, A { }; void test(C c) { ++c; // expected-error {{use of overloaded operator '++' is ambiguous}}\ - // expected-note {{built-in candidate operator ++ ('int &')}} \ - // expected-note {{built-in candidate operator ++ ('long &')}} \ - // expected-note {{built-in candidate operator ++ ('long *&')}} \ - // expected-note {{built-in candidate operator ++ ('int *&')}} + // expected-note {{built-in candidate operator++(int &)}} \ + // expected-note {{built-in candidate operator++(long &)}} \ + // expected-note {{built-in candidate operator++(long *&)}} \ + // expected-note {{built-in candidate operator++(int *&)}} } struct A1 { operator volatile int&(); }; @@ -28,7 +28,7 @@ struct C1 : B1, A1 { }; void test(C1 c) { ++c; // expected-error {{use of overloaded operator '++' is ambiguous}} \ - // expected-note {{built-in candidate operator ++ ('int volatile &')}} \ - // expected-note {{built-in candidate operator ++ ('long volatile &')}} + // expected-note {{built-in candidate operator++(int volatile &)}} \ + // expected-note {{built-in candidate operator++(long volatile &)}} } diff --git a/test/SemaCXX/builtin-ptrtomember-ambig.cpp b/test/SemaCXX/builtin-ptrtomember-ambig.cpp index 34652474f3..1b52651910 100644 --- a/test/SemaCXX/builtin-ptrtomember-ambig.cpp +++ b/test/SemaCXX/builtin-ptrtomember-ambig.cpp @@ -19,9 +19,9 @@ struct C : B { void foo(C c, int A::* pmf) { // FIXME. Why so many built-in candidates? int i = c->*pmf; // expected-error {{use of overloaded operator '->*' is ambiguous}} \ - // expected-note {{built-in candidate operator ->* ('struct A const *', 'int const struct A::*')}} \ - // expected-note {{built-in candidate operator ->* ('struct A const *', 'int struct A::*')}} \ - // expected-note {{built-in candidate operator ->* ('struct A *', 'int const struct A::*')}} \ - // expected-note {{built-in candidate operator ->* ('struct A *', 'int struct A::*')}} + // expected-note {{built-in candidate operator->*(struct A const *, int const struct A::*)}} \ + // expected-note {{built-in candidate operator->*(struct A const *, int struct A::*)}} \ + // expected-note {{built-in candidate operator->*(struct A *, int const struct A::*)}} \ + // expected-note {{built-in candidate operator->*(struct A *, int struct A::*)}} } -- 2.40.0