aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Format/UnwrappedLineParser.cpp1
-rw-r--r--unittests/Format/FormatTest.cpp11
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index 8408ce3a0d..b24d5141e0 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -822,6 +822,7 @@ void UnwrappedLineParser::readToken() {
while (!Line->InPPDirective && FormatTok.Tok.is(tok::hash) &&
((FormatTok.NewlinesBefore > 0 && FormatTok.HasUnescapedNewline) ||
FormatTok.IsFirst)) {
+ flushComments(FormatTok.NewlinesBefore > 0);
// If there is an unfinished unwrapped line, we flush the preprocessor
// directives only after that unwrapped line was finished later.
bool SwitchToPreprocessorLines =
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 7fbb9f3ac4..83c7a2adbf 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -699,6 +699,13 @@ TEST_F(FormatTest, SplitsLongCxxComments) {
"//Don't add leading\n"
"//whitespace",
format("//Don't add leading whitespace", getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("// A comment before\n"
+ "// a macro\n"
+ "// definition\n"
+ "#define a b",
+ format("// A comment before a macro definition\n"
+ "#define a b",
+ getLLVMStyleWithColumns(20)));
}
TEST_F(FormatTest, SplitsLongLinesInComments) {
@@ -1203,13 +1210,13 @@ TEST_F(FormatTest, IndentsPPDirectiveInReducedSpace) {
}
TEST_F(FormatTest, HandlePreprocessorDirectiveContext) {
- EXPECT_EQ("// some comment\n"
+ EXPECT_EQ("// somecomment\n"
"#include \"a.h\"\n"
"#define A( \\\n"
" A, B)\n"
"#include \"b.h\"\n"
"// somecomment\n",
- format(" // some comment\n"
+ format(" // somecomment\n"
" #include \"a.h\"\n"
"#define A(A,\\\n"
" B)\n"