From 16a69ef481f4580c571b6c693a5d3dd64ea56b53 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 3 May 2013 14:41:24 +0000 Subject: [PATCH] Fix expression recognition in for-loops. Before: for (; a&& b;) {} After: for (; a && b;) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181017 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 3 +++ unittests/Format/FormatTest.cpp | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 3e67182f87..6fa79813fa 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -596,6 +596,9 @@ private: Contexts.back().IsExpression = true; } else if (Current.is(tok::kw_new)) { Contexts.back().CanBeExpression = false; + } else if (Current.is(tok::semi)) { + // This should be the condition or increment in a for-loop. + Contexts.back().IsExpression = true; } if (Current.Type == TT_Unknown) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 055b9d1cb2..abb2b5819c 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2547,6 +2547,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("A a;"); verifyIndependentOfContext("void f(int *a = d * e, int *b = c * d);"); verifyFormat("for (char **a = b; *a; ++a) {\n}"); + verifyFormat("for (; a && b;) {\n}"); verifyFormat( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" -- 2.50.1