r242849 - clang-format: Fix unary operator detection in for loops.
Daniel Jasper
djasper at google.com
Tue Jul 21 15:51:01 PDT 2015
Author: djasper
Date: Tue Jul 21 17:51:00 2015
New Revision: 242849
URL: http://llvm.org/viewvc/llvm-project?rev=242849&view=rev
Log:
clang-format: Fix unary operator detection in for loops.
Before:
for (;; * a = b) {}
After:
for (;; *a = b) {}
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=242849&r1=242848&r2=242849&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Jul 21 17:51:00 2015
@@ -836,7 +836,8 @@ private:
Contexts.back().IsExpression = true;
if (!Line.startsWith(TT_UnaryOperator)) {
for (FormatToken *Previous = Current.Previous;
- Previous && !Previous->isOneOf(tok::comma, tok::semi);
+ Previous && Previous->Previous &&
+ !Previous->Previous->isOneOf(tok::comma, tok::semi);
Previous = Previous->Previous) {
if (Previous->isOneOf(tok::r_square, tok::r_paren)) {
Previous = Previous->MatchingParen;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=242849&r1=242848&r2=242849&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jul 21 17:51:00 2015
@@ -5458,6 +5458,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
FormatStyle Left = getLLVMStyle();
Left.PointerAlignment = FormatStyle::PAS_Left;
verifyFormat("x = *a(x) = *a(y);", Left);
+ verifyFormat("for (;; * = b) {\n}", Left);
verifyIndependentOfContext("a = *(x + y);");
verifyIndependentOfContext("a = &(x + y);");
More information about the cfe-commits
mailing list