[clang] [clang][Diagnostics] Fix wrong line number display (PR #65238)

Takuya Shimizu via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 4 00:13:10 PDT 2023


hazohelet wrote:

> Ouch the inability to comment outside of modified code is going to be painful.
> 
> The changed code being
> 
> ```c++
>   unsigned DisplayLineNo = Loc.getPresumedLoc().getLine();
>   for (const auto &I : Ranges) {
>   DisplayLineNo = 
>             std::min(DisplayLineNo, SM.getPresumedLineNumber(I.getBegin()));
>   }
> ```
> 
> If the range starts before `DisplayLineNo`, it still works. Am I missing something?

Thanks, that's my point.

When I provided an invalid source location, the diagnostics looked like the following. Filename, line/column number and code snippet are not printed.
```
source:7:3: error: no matching function for call to 'func'
    7 |   func(3, 4, 5);
      |   ^~~~
note: candidate function not viable: expects an lvalue for 3rd argument
1 error generated.
```
When `Loc` is invalid, calling `Loc.getPresumedLoc().getLine()` should cause validness assertion failure in `PresumedLoc::getLine`, so invalid `Loc` seems to be handled elsewhere.

https://github.com/llvm/llvm-project/pull/65238


More information about the cfe-commits mailing list