clang-format: Fix enum formatting with specific comment.
authorDaniel Jasper <djasper@google.com>
Tue, 10 Jun 2014 10:42:26 +0000 (10:42 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 10 Jun 2014 10:42:26 +0000 (10:42 +0000)
Before:
  enum Fruit {  //
    APPLE,
    PEAR };

After:
  enum Fruit {  //
    APPLE,
    PEAR
  };

llvm-svn: 210522

clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTest.cpp

index 5d59f19..6304ff7 100644 (file)
@@ -447,7 +447,9 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
 
   // If we break after { or the [ of an array initializer, we should also break
   // before the corresponding } or ].
-  if (Previous.is(tok::l_brace) || Previous.Type == TT_ArrayInitializerLSquare)
+  if (PreviousNonComment &&
+      (PreviousNonComment->is(tok::l_brace) ||
+       PreviousNonComment->Type == TT_ArrayInitializerLSquare))
     State.Stack.back().BreakBeforeClosingBrace = true;
 
   if (State.Stack.back().AvoidBinPacking) {
index 02636a7..baf05a9 100644 (file)
@@ -1900,6 +1900,10 @@ TEST_F(FormatTest, FormatsEnum) {
                    "\n"
                    "  THREE\n"
                    "}"));
+  verifyFormat("enum E { // comment\n"
+               "  ONE,\n"
+               "  TWO\n"
+               "};");
 }
 
 TEST_F(FormatTest, FormatsEnumsWithErrors) {
@@ -5410,7 +5414,8 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
       "             BracedList{ // comment 1 (Forcing interesting break)\n"
       "                         param1, param2,\n"
       "                         // comment 2\n"
-      "                         param3, param4 });",
+      "                         param3, param4\n"
+      "             });",
       ExtraSpaces);
   verifyFormat(
       "std::this_thread::sleep_for(\n"