Fix bug that would lead to joining preprocessor directives.
Before: #include "a.h" #include "b.h"
After: #include "a.h"
#include "b.h"
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172424 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index c8dc7bf..742b9a8 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -1427,7 +1427,8 @@
std::vector<AnnotatedLine>::iterator E,
unsigned Limit) {
AnnotatedLine &Line = *I;
- if (!(I + 1)->InPPDirective) return;
+ if (!(I + 1)->InPPDirective || (I + 1)->First.FormatTok.HasUnescapedNewline)
+ return;
if (I + 2 != E && (I + 2)->InPPDirective &&
!(I + 2)->First.FormatTok.HasUnescapedNewline)
return;
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index c088089..daebc4d 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1133,12 +1133,12 @@
}
TEST_F(FormatTest, HandlesIncludeDirectives) {
- verifyFormat("#include <string>");
- verifyFormat("#include <a/b/c.h>");
- verifyFormat("#include \"a/b/string\"");
- verifyFormat("#include \"string.h\"");
- verifyFormat("#include \"string.h\"");
- verifyFormat("#include <a-a>");
+ verifyFormat("#include <string>\n"
+ "#include <a/b/c.h>\n"
+ "#include \"a/b/string\"\n"
+ "#include \"string.h\"\n"
+ "#include \"string.h\"\n"
+ "#include <a-a>");
verifyFormat("#import <string>");
verifyFormat("#import <a/b/c.h>");