@@ -273,6 +273,13 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
273273 // Which overload candidates to show.
274274 OverloadsShown ShowOverloads = Ovl_All;
275275
276+ // With Ovl_Best, the number of overload candidates to show when we encounter
277+ // an error.
278+ //
279+ // The value here is the number of candidates to show in the first nontrivial
280+ // error. Future errors may show a different number of candidates.
281+ unsigned NumOverloadsToShow = 32 ;
282+
276283 // Cap of # errors emitted, 0 -> no limit.
277284 unsigned ErrorLimit = 0 ;
278285
@@ -707,6 +714,36 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
707714 }
708715 OverloadsShown getShowOverloads () const { return ShowOverloads; }
709716
717+ // / When a call or operator fails, print out up to this many candidate
718+ // / overloads as suggestions.
719+ // /
720+ // / With Ovl_Best, we set a high limit for the first nontrivial overload set
721+ // / we print, and a lower limit for later sets. This way the user has a
722+ // / chance of diagnosing at least one callsite in their program without
723+ // / having to recompile with -fshow-overloads=all.
724+ unsigned getNumOverloadCandidatesToShow () const {
725+ switch (getShowOverloads ()) {
726+ case Ovl_All:
727+ // INT_MAX rather than UINT_MAX so that we don't have to think about the
728+ // effect of implicit conversions on this value. In practice we'll never
729+ // hit 2^31 candidates anyway.
730+ return std::numeric_limits<int >::max ();
731+ case Ovl_Best:
732+ return NumOverloadsToShow;
733+ }
734+ }
735+
736+ // / Call this after showing N overload candidates. This influences the value
737+ // / returned by later calls to getNumOverloadCandidatesToShow().
738+ void overloadCandidatesShown (unsigned N) {
739+ // Current heuristic: Start out with a large value for NumOverloadsToShow,
740+ // and then once we print one nontrivially-large overload set, decrease it
741+ // for future calls.
742+ if (N > 4 ) {
743+ NumOverloadsToShow = 4 ;
744+ }
745+ }
746+
710747 // / Pretend that the last diagnostic issued was ignored, so any
711748 // / subsequent notes will be suppressed, or restore a prior ignoring
712749 // / state after ignoring some diagnostics and their notes, possibly in
0 commit comments