]> granicus.if.org Git - clang/commitdiff
clang-format: Fix unary operator detection in for loops.
authorDaniel Jasper <djasper@google.com>
Tue, 21 Jul 2015 22:51:00 +0000 (22:51 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 21 Jul 2015 22:51:00 +0000 (22:51 +0000)
Before:
  for (;; * a = b) {}

After:
  for (;; *a = b) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242849 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 55f5b103f99e56d427b4f570a2f8db1400e73289..36856eaeea97eca9c6b9d050657b0adf639f0a0a 100644 (file)
@@ -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;
index 252ae4db3f82e73607f41226bcc447683163971c..9cb1c31b055ffa7691eb51b0a7a789b09e6f8da7 100644 (file)
@@ -5458,6 +5458,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   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);");