Now that clang supports printing of multiple lines of code snippet in diagnostics, source ranges in diagnostics that are located in different lines from the diagnosed source location get to be printed if the gap happened to be less than the maximum number of lines clang is allowed to print in.
Many of the bad-conversion notes in overload resolution failures have their source location in the function declaration and source range in the argument of function call. This can cause an unnecessarily many lines of snippet printing.
This patch fixes it by changing the source range from function callsite to the problematic parameter in function declaration.
e.g.
void func(int aa, int bb); void test() { func(1, "two"); }
BEFORE this patch:
source:4:15: error: no matching function for call to 'func' 4 | void test() { func(1, "two"); } | ^~~~ source:1:6: note: candidate function not viable: no known conversion from 'const char[4]' to 'int' for 2nd argument 1 | void func(int aa, int bb); | ^ 2 | 3 | 4 | void test() { func(1, "two"); } | ~~~~~ 1 error generated.
AFTER this patch:
source:4:15: error: no matching function for call to 'func' 4 | void test() { func(1, "two"); } | ^~~~ source:1:6: note: candidate function not viable: no known conversion from 'const char[4]' to 'int' for 2nd argument 1 | void func(int aa, int bb); | ^ ~~~~~~
Can this be const?