summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/TokenAnnotator.h6
-rw-r--r--clang/unittests/Format/FormatTest.cpp13
2 files changed, 19 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.h b/clang/lib/Format/TokenAnnotator.h
index 91f1b4678a1..e51003bac82 100644
--- a/clang/lib/Format/TokenAnnotator.h
+++ b/clang/lib/Format/TokenAnnotator.h
@@ -43,6 +43,11 @@ public:
MustBeDeclaration(Line.MustBeDeclaration), MightBeFunctionDecl(false),
StartsDefinition(false) {
assert(!Line.Tokens.empty());
+
+ // Calculate Next and Previous for all tokens. Note that we must overwrite
+ // Next and Previous for every token, as previous formatting runs might have
+ // left them in a different state.
+ First->Previous = NULL;
FormatToken *Current = First;
for (std::list<UnwrappedLineNode>::const_iterator I = ++Line.Tokens.begin(),
E = Line.Tokens.end();
@@ -60,6 +65,7 @@ public:
}
}
Last = Current;
+ Last->Next = NULL;
}
~AnnotatedLine() {
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 6a2d0d89b4c..a7de81b2678 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2329,6 +2329,19 @@ TEST_F(FormatTest, LayoutStatementsAroundPreprocessorDirectives) {
"int i;");
}
+TEST_F(FormatTest, FormatsJoinedLinesOnSubsequentRuns) {
+ FormatStyle SingleLine = getLLVMStyle();
+ SingleLine.AllowShortIfStatementsOnASingleLine = true;
+ verifyFormat(
+ "#if 0\n"
+ "#elif 1\n"
+ "#endif\n"
+ "void foo() {\n"
+ " if (test) foo2();\n"
+ "}",
+ SingleLine);
+}
+
TEST_F(FormatTest, LayoutBlockInsideParens) {
EXPECT_EQ("functionCall({ int i; });", format(" functionCall ( {int i;} );"));
EXPECT_EQ("functionCall({\n"
OpenPOWER on IntegriCloud