]> granicus.if.org Git - clang/commitdiff
clang-format: Correctly identify multiplications in braces init lists.
authorDaniel Jasper <djasper@google.com>
Thu, 22 May 2014 09:00:33 +0000 (09:00 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 22 May 2014 09:00:33 +0000 (09:00 +0000)
Before:
  int i{a *b};

After:
  int i{a * b};

Also fix unrelated issue where braced init lists were counted as blocks
and prevented single-line functions.

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

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

index 03177e586ad03adc1af5dd530a6e0ca7bda6d8de..471af1d5393eeca13dedacdf72e77b52cc3c8366 100644 (file)
@@ -690,7 +690,7 @@ private:
       if (I[1]->Last->Type == TT_LineComment)
         return 0;
       do {
-        if (Tok->isOneOf(tok::l_brace, tok::r_brace) &&
+        if (Tok->is(tok::l_brace) && Tok->BlockKind != BK_BracedInit &&
             !Style.AllowShortBlocksOnASingleLine)
           return 0;
         Tok = Tok->Next;
index dca20d2d75db2b2c12197c100d133feaf95d2ccb..f3d655ace5bb67ff10f15ca10f1ade49e90ecdeb 100644 (file)
@@ -298,6 +298,8 @@ private:
 
       ScopedContextCreator ContextCreator(*this, tok::l_brace, 1);
       Contexts.back().ColonIsDictLiteral = true;
+      if (Left->BlockKind == BK_BracedInit)
+        Contexts.back().IsExpression = true;
 
       while (CurrentToken) {
         if (CurrentToken->is(tok::r_brace)) {
index 3dbada81f01173388963731bd993158b3d9660c4..af0b5a1cb61ca748a32d02b701ae07c3a03711eb 100644 (file)
@@ -4694,6 +4694,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("auto PointerBinding = [](const char *S) {};");
   verifyFormat("typedef typeof(int(int, int)) *MyFunc;");
   verifyIndependentOfContext("typedef void (*f)(int *a);");
+  verifyIndependentOfContext("int i{a * b};");
 
   verifyIndependentOfContext("InvalidRegions[*R] = 0;");
 
@@ -7044,9 +7045,7 @@ TEST_F(FormatTest, DoNotCreateUnreasonableUnwrappedLines) {
 
 TEST_F(FormatTest, DoNotPrematurelyEndUnwrappedLineForReturnStatements) {
   verifyFormat(
-      "void f() {\n"
-      "  return C{param1, param2}.SomeCall(param1, param2);\n"
-      "}\n");
+      "void f() { return C{param1, param2}.SomeCall(param1, param2); }");
 }
 
 TEST_F(FormatTest, FormatsClosingBracesInEmptyNestedBlocks) {