r238182 - clang-format: Fix child-formatting in macros.
Daniel Jasper
djasper at google.com
Tue May 26 00:03:42 PDT 2015
Author: djasper
Date: Tue May 26 02:03:42 2015
New Revision: 238182
URL: http://llvm.org/viewvc/llvm-project?rev=238182&view=rev
Log:
clang-format: Fix child-formatting in macros.
This fixes a case where the column limit was incorrectly calculated
leading to a macro like this:
#define A \
[] { \
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx( \
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx); \
}
exceeding the column limit.
Modified:
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=238182&r1=238181&r2=238182&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Tue May 26 02:03:42 2015
@@ -934,10 +934,14 @@ UnwrappedLineFormatter::getColumnLimit(b
// In preprocessor directives reserve two chars for trailing " \" if the
// next line continues the preprocessor directive.
bool ContinuesPPDirective =
- InPPDirective && NextLine && NextLine->InPPDirective &&
- // If there is an unescaped newline between this line and the next, the
- // next line starts a new preprocessor directive.
- !NextLine->First->HasUnescapedNewline;
+ InPPDirective &&
+ // If there is no next line, this is likely a child line and the parent
+ // continues the preprocessor directive.
+ (!NextLine ||
+ (NextLine->InPPDirective &&
+ // If there is an unescaped newline between this line and the next, the
+ // next line starts a new preprocessor directive.
+ !NextLine->First->HasUnescapedNewline));
return Style.ColumnLimit - (ContinuesPPDirective ? 2 : 0);
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=238182&r1=238181&r2=238182&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue May 26 02:03:42 2015
@@ -3303,6 +3303,15 @@ TEST_F(FormatTest, FormatNestedBlocksInM
format("#define MACRO() Debug(aaa, /* force line break */ \\\n"
" { int i; int j; })",
getGoogleStyle()));
+
+ EXPECT_EQ("#define A \\\n"
+ " [] { \\\n"
+ " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx( \\\n"
+ " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx); \\\n"
+ " }",
+ format("#define A [] { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx( \\\n"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx); }",
+ getGoogleStyle()));
}
TEST_F(FormatTest, IndividualStatementsOfNestedBlocks) {
More information about the cfe-commits
mailing list