aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/TextDiagnosticPrinter.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-05-03 04:33:32 +0000
committerDouglas Gregor <dgregor@apple.com>2009-05-03 04:33:32 +0000
commit844da34736c0439ae50017826a7393406e75acd8 (patch)
tree43ac2ac218e6efa6d33eab625497d7edb248dab1 /lib/Frontend/TextDiagnosticPrinter.cpp
parent7d101f6fd7f311b0a7fdd83a50f8668bd8a659cd (diff)
When a fix-it hint would span multiple lines, don't print it; half a
fix-it hint is much worse than no fix-it hint. (Fixes PR4084). When we need to truncate a source line to fix in the terminal, make sure to take the width of the fix-it information into account, too. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70656 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/TextDiagnosticPrinter.cpp')
-rw-r--r--lib/Frontend/TextDiagnosticPrinter.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp
index bcf30a5f56..a2cf8f958c 100644
--- a/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -132,7 +132,25 @@ static void SelectInterestingSourceRegion(std::string &SourceLine,
for (; CaretEnd != CaretStart; --CaretEnd)
if (!isspace(CaretLine[CaretEnd - 1]))
break;
+
+ // If we have a fix-it line, make sure the slice includes all of the
+ // fix-it information.
+ if (!FixItInsertionLine.empty()) {
+ unsigned FixItStart = 0, FixItEnd = FixItInsertionLine.size();
+ for (; FixItStart != FixItEnd; ++FixItStart)
+ if (!isspace(FixItInsertionLine[FixItStart]))
+ break;
+ for (; FixItEnd != FixItStart; --FixItEnd)
+ if (!isspace(FixItInsertionLine[FixItEnd - 1]))
+ break;
+
+ if (FixItStart < CaretStart)
+ CaretStart = FixItStart;
+ if (FixItEnd > CaretEnd)
+ CaretEnd = FixItEnd;
+ }
+
// CaretLine[CaretStart, CaretEnd) contains all of the interesting
// parts of the caret line. While this slice is smaller than the
// number of columns we have, try to grow the slice to encompass
@@ -379,6 +397,9 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
FixItInsertionLine.resize(LastColumnModified, ' ');
std::copy(Hint->CodeToInsert.begin(), Hint->CodeToInsert.end(),
FixItInsertionLine.begin() + HintColNo - 1);
+ } else {
+ FixItInsertionLine.clear();
+ break;
}
}
}