clang-format: Improve handling of unterminated string literals.
Before, clang-format would simply eat these as they were recognized as
whitespace. With this patch, they are mostly left alone.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186454 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 7a2364c..6f6f468 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -948,13 +948,14 @@
Current->SpacesRequiredBefore =
spaceRequiredBefore(Line, *Current) ? 1 : 0;
- if (Current->MustBreakBefore) {
- } else if (Current->is(tok::comment)) {
+ if (Current->is(tok::comment)) {
Current->MustBreakBefore = Current->NewlinesBefore > 0;
} else if (Current->Previous->isTrailingComment() ||
(Current->is(tok::string_literal) &&
Current->Previous->is(tok::string_literal))) {
Current->MustBreakBefore = true;
+ } else if (Current->Previous->IsUnterminatedLiteral) {
+ Current->MustBreakBefore = true;
} else if (Current->is(tok::lessless) && Current->Next &&
Current->Previous->is(tok::string_literal) &&
Current->Next->is(tok::string_literal)) {
@@ -969,8 +970,6 @@
Current->getNextNonComment() &&
Current->getNextNonComment()->is(tok::string_literal)) {
Current->MustBreakBefore = true;
- } else {
- Current->MustBreakBefore = false;
}
Current->CanBreakBefore =
Current->MustBreakBefore || canBreakBefore(Line, *Current);