[cfe-commits] [PATCH] Add smarter sorting of overload candidates that failed template deduction
Kaelyn Uhrain
rikka at google.com
Fri Sep 9 10:56:14 PDT 2011
On Fri, Sep 9, 2011 at 10:33 AM, Douglas Gregor <dgregor at apple.com> wrote:
>
> On Sep 8, 2011, at 4:43 PM, Kaelyn Uhrain wrote:
>
> > Given a file tmp.cpp containing:
> >
> > [snip example]
> >
> > When Clang emits the error about not finding a match for that call to f
> because exit is an overloaded function, Clang currently emits notes for all
> of the function template candidates in lexical order, to where the "closest"
> failing match is the 6th note of 9 with 3 candidates that require a
> different number of arguments listed before it:
> >
> > [snip example]
> >
> >
> > This small patch adds rankings to the different types of template
> deduction failure (all of the OverloadCandidates above have a base
> FailureKind of ovl_fail_bad_deduction), so that e.g. a candidate where a
> template argument could not be inferred is listed before a candidate that
> requires the wrong number of arguments. So for the above code example, the
> output becomes:
> >
> > [snip much-improved example]
> >
> > While the text of the note still isn't particularly useful for figuring
> out what failed, it at least gives a little better clue as to where the
> problem lies (in this example, the problem is rooted in there being two
> different single-argument declarations of "exit"). Feedback is both welcome
> and desired, especially on the ranking of the different types of deduction
> failures.
>
>
> I like this a lot! We could bike-shed on the specific rankings a lot, so
> I'll just make a few comments about the ranking:
>
> - TDK_InvalidExplicitArguments should, IMO, have a fairly poor
> ranking (4 or 5), because users are being very explicit about these
> arguments and the you generally have to be *very* wrong for template
> arguments to not match their template parameters (e.g., providing an
> expression where a type was expected)
>
I moved TDK_InvalidExplicitArguments to rank 5 and made TDK_Too*Arguments
rank 6 since I feel it's slightly more likely that someone gave the wrong
argument to a template than to have the wrong number of arguments (with
candidates needing the wrong number of arguments being a more common case,
especially candidates that are way way out in left field).
- I suggest that TDK_SubstitutionFailure and TDK_NonDeducedMismatch
> should move up to rank 3, because these can often mean some little failure
> at the call site
>
Done!
>
> + default:
> + return UINT_MAX;
> + }
>
> Why do we need a default here?
>
Because I failed to realize all of the TemplateDeductionResult enum values
were already handled. I've removed it. ;)
Thanks for the feedback!
Cheers,
Kaelyn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110909/a6e3cb13/attachment.html>
More information about the cfe-commits
mailing list