[cfe-commits] r167596 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/SemaCXX/ambiguous-conversion-show-overload.cpp
Matt Beaumont-Gay
matthewbg at google.com
Thu Nov 8 12:50:02 PST 2012
Author: matthewbg
Date: Thu Nov 8 14:50:02 2012
New Revision: 167596
URL: http://llvm.org/viewvc/llvm-project?rev=167596&view=rev
Log:
Fix a bug I found while preparing my devmtg talk: When passing NULL to a
function that takes a const Foo&, where Foo is convertible from a large number
of pointer types, we print ALL the overloads, no matter the setting of
-fshow-overloads.
There is potential follow-on work in unifying the "print candidates, but not
too many" logic between OverloadCandidateSet::NoteCandidates and
ImplicitConversionSequence::DiagnoseAmbiguousConversion.
Added:
cfe/trunk/test/SemaCXX/ambiguous-conversion-show-overload.cpp
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=167596&r1=167595&r2=167596&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Nov 8 14:50:02 2012
@@ -7992,10 +7992,20 @@
const PartialDiagnostic &PDiag) const {
S.Diag(CaretLoc, PDiag)
<< Ambiguous.getFromType() << Ambiguous.getToType();
- for (AmbiguousConversionSequence::const_iterator
- I = Ambiguous.begin(), E = Ambiguous.end(); I != E; ++I) {
+ // FIXME: The note limiting machinery is borrowed from
+ // OverloadCandidateSet::NoteCandidates; there's an opportunity for
+ // refactoring here.
+ const OverloadsShown ShowOverloads = S.Diags.getShowOverloads();
+ unsigned CandsShown = 0;
+ AmbiguousConversionSequence::const_iterator I, E;
+ for (I = Ambiguous.begin(), E = Ambiguous.end(); I != E; ++I) {
+ if (CandsShown >= 4 && ShowOverloads == Ovl_Best)
+ break;
+ ++CandsShown;
S.NoteOverloadCandidate(*I);
}
+ if (I != E)
+ S.Diag(SourceLocation(), diag::note_ovl_too_many_candidates) << int(E - I);
}
namespace {
Added: cfe/trunk/test/SemaCXX/ambiguous-conversion-show-overload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ambiguous-conversion-show-overload.cpp?rev=167596&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/ambiguous-conversion-show-overload.cpp (added)
+++ cfe/trunk/test/SemaCXX/ambiguous-conversion-show-overload.cpp Thu Nov 8 14:50:02 2012
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -fshow-overloads=best -fno-caret-diagnostics %s 2>&1 | FileCheck %s
+struct S {
+ S(void*);
+ S(char*);
+ S(unsigned char*);
+ S(signed char*);
+ S(unsigned short*);
+ S(signed short*);
+ S(unsigned int*);
+ S(signed int*);
+};
+void f(const S& s);
+void g() {
+ f(0);
+}
+// CHECK: {{conversion from 'int' to 'const S' is ambiguous}}
+// CHECK-NEXT: {{candidate constructor}}
+// CHECK-NEXT: {{candidate constructor}}
+// CHECK-NEXT: {{candidate constructor}}
+// CHECK-NEXT: {{candidate constructor}}
+// CHECK-NEXT: {{remaining 4 candidates omitted; pass -fshow-overloads=all to show them}}
More information about the cfe-commits
mailing list