]> granicus.if.org Git - clang/commitdiff
clang-format: Fix bug in pointer detection
authorDaniel Jasper <djasper@google.com>
Wed, 11 Sep 2013 20:37:10 +0000 (20:37 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 11 Sep 2013 20:37:10 +0000 (20:37 +0000)
Before:
  for (int i = 0; i* 2 < z; i *= 2) {}
After:
  for (int i = 0; i * 2 < z; i *= 2) {}

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

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

index f10e68c3405a83d70ce63f049806b23206d4be89..dec631fcfb3bb68c37701751aafdb1f9716153c0 100644 (file)
@@ -574,7 +574,7 @@ private:
         (!Current.Previous || Current.Previous->isNot(tok::kw_operator))) {
       Contexts.back().IsExpression = true;
       for (FormatToken *Previous = Current.Previous;
-           Previous && Previous->isNot(tok::comma);
+           Previous && !Previous->isOneOf(tok::comma, tok::semi);
            Previous = Previous->Previous) {
         if (Previous->is(tok::r_square))
           Previous = Previous->MatchingParen;
index 00ece1a6594036bb6a40adb6b678003c2db1beb7..2500c8e4a714f2371ea8d0c7bc99e1e4af069815 100644 (file)
@@ -3825,6 +3825,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
                "}");
   verifyFormat("for (int i = a * a; i < 10; ++i) {\n}");
   verifyFormat("for (int i = 0; i < a * a; ++i) {\n}");
+  verifyGoogleFormat("for (int i = 0; i * 2 < z; i *= 2) {\n}");
 
   verifyFormat("#define MACRO     \\\n"
                "  int *i = a * b; \\\n"