r210522 - clang-format: Fix enum formatting with specific comment.
Daniel Jasper
djasper at google.com
Tue Jun 10 03:42:26 PDT 2014
Author: djasper
Date: Tue Jun 10 05:42:26 2014
New Revision: 210522
URL: http://llvm.org/viewvc/llvm-project?rev=210522&view=rev
Log:
clang-format: Fix enum formatting with specific comment.
Before:
enum Fruit { //
APPLE,
PEAR };
After:
enum Fruit { //
APPLE,
PEAR
};
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=210522&r1=210521&r2=210522&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Jun 10 05:42:26 2014
@@ -447,7 +447,9 @@ unsigned ContinuationIndenter::addTokenO
// 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) {
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=210522&r1=210521&r2=210522&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jun 10 05:42:26 2014
@@ -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, LayoutCxx11BraceIniti
" 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"
More information about the cfe-commits
mailing list