[clang] [clang] Add Bytes/Column types to TextDiagnostic (PR #165541)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 29 05:01:07 PDT 2025
================
@@ -1379,35 +1440,36 @@ void TextDiagnostic::emitSnippetAndCaret(
std::string SourceLine(LineStart, LineEnd);
// Remove trailing null bytes.
while (!SourceLine.empty() && SourceLine.back() == '\0' &&
- (LineNo != CaretLineNo || SourceLine.size() > CaretColNo))
+ (LineNo != CaretLineNo ||
+ SourceLine.size() > static_cast<size_t>(CaretByte.V)))
SourceLine.pop_back();
// Build the byte to column map.
- const SourceColumnMap sourceColMap(SourceLine, DiagOpts.TabStop);
+ const SourceColumnMap SourceColMap(SourceLine, DiagOpts.TabStop);
std::string CaretLine;
// Highlight all of the characters covered by Ranges with ~ characters.
for (const auto &LR : LineRanges) {
if (LR.LineNo == LineNo)
- highlightRange(LR, sourceColMap, CaretLine);
+ highlightRange(LR, SourceColMap, CaretLine);
}
// Next, insert the caret itself.
if (CaretLineNo == LineNo) {
- size_t Col = sourceColMap.byteToContainingColumn(CaretColNo - 1);
- CaretLine.resize(std::max(Col + 1, CaretLine.size()), ' ');
- CaretLine[Col] = '^';
+ Columns Col = SourceColMap.byteToContainingColumn(CaretByte.prev());
+ CaretLine.resize(std::max((size_t)Col.V + 1, CaretLine.size()), ' ');
----------------
Sirraide wrote:
```suggestion
CaretLine.resize(std::max(static_cast<size_t>(Col.V) + 1, CaretLine.size()), ' ');
```
https://github.com/llvm/llvm-project/pull/165541
More information about the cfe-commits
mailing list