summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-05-26 07:03:42 +0000
committerDaniel Jasper <djasper@google.com>2015-05-26 07:03:42 +0000
commit1a028227041034ea7c8e8f1826a97d18dab32e89 (patch)
tree8dc3564ad73f6cdba5c94ce3175fd88afed8dee1 /clang
parente59cd0b9ec44f5ae514634c6f08d12ac9fe0a815 (diff)
downloadbcm5719-llvm-1a028227041034ea7c8e8f1826a97d18dab32e89.tar.gz
bcm5719-llvm-1a028227041034ea7c8e8f1826a97d18dab32e89.zip
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. llvm-svn: 238182
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.cpp12
-rw-r--r--clang/unittests/Format/FormatTest.cpp9
2 files changed, 17 insertions, 4 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 9c8b5ba08eb..cbf8c6c9221 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -934,10 +934,14 @@ UnwrappedLineFormatter::getColumnLimit(bool InPPDirective,
// 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);
}
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 4684d1d746b..5100c8e9304 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -3303,6 +3303,15 @@ TEST_F(FormatTest, FormatNestedBlocksInMacros) {
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) {
OpenPOWER on IntegriCloud