Implement -fmessage-length=N, which word-wraps diagnostics to N columns.
Also, put a line of whitespace between the diagnostic and the source
code/caret line when the start of the actual source code text lines up
(or nearly lines up) with the most recent line of the diagnostic. For
example, here it's okay for the last line of the diagnostic to be
(vertically) next to the source line, because there is horizontal
whitespace to separate them:
decl-expr-ambiguity.cpp:12:16: error: function-style cast to a builtin
type can only take one argument
typeof(int)(a,5)<<a;
However, here is a case where we need the vertical separation (since
there is no horizontal separation):
message-length.c:10:46: warning: incompatible pointer types initializing 'void
(int, float, char, float)', expected 'int (*)(int, float, short,
float)'
int (*fp1)(int, float, short, float) = f;
This is part one of <rdar://problem/6711348>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70578 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 1fa49c1..12a537b 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -319,6 +319,12 @@
PrintDiagnosticOption("fdiagnostics-show-option",
llvm::cl::desc("Print diagnostic name with mappable diagnostics"));
+static llvm::cl::opt<unsigned>
+MessageLength("fmessage-length",
+ llvm::cl::desc("Format message diagnostics so that they fit "
+ "within N columns or fewer, when possible."),
+ llvm::cl::value_desc("N"));
+
//===----------------------------------------------------------------------===//
// C++ Visualization.
//===----------------------------------------------------------------------===//
@@ -1481,7 +1487,8 @@
!NoShowLocation,
PrintSourceRangeInfo,
PrintDiagnosticOption,
- !NoDiagnosticsFixIt));
+ !NoDiagnosticsFixIt,
+ MessageLength));
}
virtual void setLangOptions(const LangOptions *LO) {
@@ -1893,7 +1900,8 @@
!NoShowLocation,
PrintSourceRangeInfo,
PrintDiagnosticOption,
- !NoDiagnosticsFixIt));
+ !NoDiagnosticsFixIt,
+ MessageLength));
} else {
DiagClient.reset(CreateHTMLDiagnosticClient(HTMLDiag));
}