diff options
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 5 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 4 |
2 files changed, 9 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 8e42e3f068f..85eec62a39c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1116,6 +1116,11 @@ private: (!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) { Contexts.back().FirstStartOfName = &Current; Current.Type = TT_StartOfName; + } else if (Current.is(tok::semi)) { + // Reset FirstStartOfName after finding a semicolon so that a for loop + // with multiple increment statements is not confused with a for loop + // having multiple variable declarations. + Contexts.back().FirstStartOfName = nullptr; } else if (Current.isOneOf(tok::kw_auto, tok::kw___auto_type)) { AutoFound = true; } else if (Current.is(tok::arrow) && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index bdce0304f97..e0815e7fd06 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -657,6 +657,10 @@ TEST_F(FormatTest, FormatsForLoop) { " I != E;\n" " ++I) {\n}", NoBinPacking); + + FormatStyle AlignLeft = getLLVMStyle(); + AlignLeft.PointerAlignment = FormatStyle::PAS_Left; + verifyFormat("for (A* a = start; a < end; ++a, ++value) {\n}", AlignLeft); } TEST_F(FormatTest, RangeBasedForLoops) { |