aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Frontend/TextDiagnosticPrinter.cpp5
-rw-r--r--test/Misc/diag-line-wrapping.cpp13
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp
index 1f6ea30c7d..64a5c1bc9c 100644
--- a/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -1097,7 +1097,7 @@ static bool printWordWrapped(raw_ostream &OS, StringRef Str,
unsigned Columns,
unsigned Column = 0,
unsigned Indentation = WordWrapIndentation) {
- const unsigned Length = Str.size();
+ const unsigned Length = std::min(Str.find('\n'), Str.size());
// The string used to indent each line.
llvm::SmallString<16> IndentStr;
@@ -1135,6 +1135,9 @@ static bool printWordWrapped(raw_ostream &OS, StringRef Str,
Wrapped = true;
}
+ // Append any remaning text from the message with its existing formatting.
+ OS << Str.substr(Length);
+
return Wrapped;
}
diff --git a/test/Misc/diag-line-wrapping.cpp b/test/Misc/diag-line-wrapping.cpp
new file mode 100644
index 0000000000..830aa13408
--- /dev/null
+++ b/test/Misc/diag-line-wrapping.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -fmessage-length 60 %s 2>&1 | FileCheck %s
+
+struct B { void f(); };
+struct D1 : B {};
+struct D2 : B {};
+struct DD : D1, D2 {
+ void g() { f(); }
+ // Ensure that after line-wrapping takes place, we preserve artificial
+ // newlines introduced to manually format a section of the diagnostic text.
+ // CHECK: {{.*}}: error:
+ // CHECK: struct DD -> struct D1 -> struct B
+ // CHECK: struct DD -> struct D2 -> struct B
+}