]> granicus.if.org Git - clang/commitdiff
Reduce penalty for splitting after "{" in static initializers.
authorDaniel Jasper <djasper@google.com>
Thu, 28 Feb 2013 15:04:12 +0000 (15:04 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 28 Feb 2013 15:04:12 +0000 (15:04 +0000)
This fixes llvm.org/PR15379.

Before:
const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = { 0x00, 0x00, 0x00, 0x00, 0x00,
                                            0x00,                  // comment
                                            0x00, 0x00, 0x00, 0x00, 0x00,
                                            0x00,                  // comment
                                            0x00, 0x00, 0x00, 0x00 // comment
};

After:
const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment
  0x00, 0x00, 0x00, 0x00              // comment
};

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

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

index e127f4af8e5d7679d8d68eec58a773ed6131025e..b9e35126ec122e9a20457ed87759ad5d32762af8 100644 (file)
@@ -880,8 +880,6 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
     else
       return 100;
   }
-  if (Left.is(tok::l_brace) && Right.isNot(tok::l_brace))
-    return 50;
   if (Left.is(tok::equal) && Right.is(tok::l_brace))
     return 150;
   if (Left.is(tok::coloncolon))
@@ -917,7 +915,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
     return 20;
 
   if (Left.is(tok::l_paren) || Left.is(tok::l_square) ||
-      Left.Type == TT_TemplateOpener)
+      Left.is(tok::l_brace) || Left.Type == TT_TemplateOpener)
     return 20;
 
   if (Right.is(tok::lessless)) {
index 392548dc6cc62cb448aea5aec241a917c63844c0..baeb0143bc328fa28f5d61bf4bfad940761f50dd 100644 (file)
@@ -612,6 +612,11 @@ TEST_F(FormatTest, CommentsInStaticInitializers) {
                                       "\n"
                                       "  b\n"
                                       "};"));
+  verifyFormat("const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = {\n"
+               "  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment\n"
+               "  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment\n"
+               "  0x00, 0x00, 0x00, 0x00              // comment\n"
+               "};");
 }
 
 //===----------------------------------------------------------------------===//