From 352dae199ae80adcaf6aed485d687fc8714fe36d Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 3 Jan 2014 11:50:46 +0000 Subject: [PATCH] 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 --- clang/lib/Format/UnwrappedLineParser.cpp | 2 +- clang/unittests/Format/FormatTest.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 90fe3bd78607..0087e5eabe78 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 66b54ab9d21d..232a06355810 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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"