clang-format: Recognize single-line macro usages inside macros.

Before:
  #define LIST(L)                                                     \
    L(FirstElement) L(SecondElement) L(ThirdElement) L(FourthElement) \
        L(FifthElement)

After:
  #define LIST(L)    \
    L(FirstElement)  \
    L(SecondElement) \
    L(ThirdElement)  \
    L(FourthElement) \
    L(FifthElement)

llvm-svn: 198407
This commit is contained in:
Daniel Jasper 2014-01-03 11:50:46 +00:00
parent b045d8bc07
commit 352dae199a
2 changed files with 12 additions and 1 deletions

View File

@ -719,7 +719,7 @@ void UnwrappedLineParser::parseStructuralElement() {
// Recognize function-like macro usages without trailing semicolon.
if (FormatTok->Tok.is(tok::l_paren)) {
parseParens();
if (FormatTok->HasUnescapedNewline &&
if (FormatTok->NewlinesBefore > 0 &&
tokenCanStartNewLine(FormatTok->Tok)) {
addUnwrappedLine();
return;

View File

@ -2198,6 +2198,17 @@ TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) {
" IPC_END_MESSAGE_MAP()\n"
"}"));
// Same inside macros.
EXPECT_EQ("#define LIST(L) \\\n"
" L(A) \\\n"
" L(B) \\\n"
" L(C)",
format("#define LIST(L) \\\n"
" L(A) \\\n"
" L(B) \\\n"
" L(C)",
getGoogleStyle()));
// These must not be recognized as macros.
EXPECT_EQ("int q() {\n"
" f(x);\n"