]> granicus.if.org Git - clang/commitdiff
clang-format: Properly handle braced lists in macros.
authorDaniel Jasper <djasper@google.com>
Mon, 24 Aug 2015 13:23:37 +0000 (13:23 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 24 Aug 2015 13:23:37 +0000 (13:23 +0000)
Before:
  #define A    \
      { a, a } \
      ,

After:
  #define A {a, a},

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

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index 1bea7a9500e3af3fe55b3c0cc98c77626266f8ba..e628072c6392e083c26f4e9185179d1de75fbfd2 100644 (file)
@@ -284,6 +284,8 @@ void UnwrappedLineParser::parseLevel(bool HasOpeningBrace) {
     case tok::l_brace:
       // FIXME: Add parameter whether this can happen - if this happens, we must
       // be in a non-declaration context.
+      if (!FormatTok->is(TT_MacroBlockBegin) && tryToParseBracedList())
+        continue;
       parseBlock(/*MustBeDeclaration=*/false);
       addUnwrappedLine();
       break;
index 3f1dc59d9337b44b6487214ddf68e6d90f498496..0f4e46436b47876948beae39653175b86620e879 100644 (file)
@@ -6144,6 +6144,7 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
                "    void f() { int i{2}; }\n"
                "  };\n"
                "};");
+  verifyFormat("#define A {a, a},");
 
   // In combination with BinPackArguments = false.
   FormatStyle NoBinPacking = getLLVMStyle();