[PATCH] D153359: [clang][Diagnostics] Fix distant source ranges in bad-conversion notes

Takuya Shimizu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 20 23:29:15 PDT 2023


hazohelet marked 2 inline comments as done.
hazohelet added a comment.

Consider the following code. (I added another parameter to the original code so that the covered range becomes clearer)

  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"); }
        |                       ~~~~~

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);
        |      ^            ~~~~~~



================
Comment at: clang/lib/Sema/SemaOverload.cpp:10752
   QualType ToTy = Conv.Bad.getToType();
+  ParmVarDecl *ToPVD = !isObjectArgument ? Fn->getParamDecl(I) : nullptr;
 
----------------
tbaeder wrote:
> tbaeder wrote:
> > Can this be `const`?
> Actually, `ToPVD` is only used to access its source range later, isn't it? If so, can we just declare the a `ToPVDRange` or something here and use that later for diagnostics?
Right. I fixed it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153359/new/

https://reviews.llvm.org/D153359



More information about the cfe-commits mailing list