[PATCH] D95479: [clang-format] Avoid considering include directive as a template closer.
Marek Kurdej via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 26 13:19:51 PST 2021
curdeius created this revision.
curdeius added reviewers: MyDeveloperDay, leonardchan.
curdeius requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This fixes a bug introduced in D93839 <https://reviews.llvm.org/D93839> where:
#include <stdint.h>
namespace rep {}
got formatted as
#include <stdint.h>
namespace rep {
}
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D95479
Files:
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10248,6 +10248,21 @@
"{\n"
"};",
Style);
+
+ verifyFormat("#include \"stdint.h\"\n"
+ "namespace rep {}",
+ Style);
+ verifyFormat("#include <stdint.h>\n"
+ "namespace rep {}",
+ Style);
+ verifyFormat("#include <stdint.h>\n"
+ "namespace rep {}",
+ "#include <stdint.h>\n"
+ "namespace rep {\n"
+ "\n"
+ "\n"
+ "}",
+ Style);
}
TEST_F(FormatTest, SplitEmptyStruct) {
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -371,7 +371,7 @@
if (Previous->is(tok::comment))
Previous = Previous->getPreviousNonComment();
if (Previous) {
- if (Previous->is(tok::greater))
+ if (Previous->is(tok::greater) && !I[-1]->InPPDirective)
return 0;
if (Previous->is(tok::identifier)) {
const FormatToken *PreviousPrevious =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95479.319399.patch
Type: text/x-patch
Size: 1369 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210126/5a6ecf66/attachment.bin>
More information about the cfe-commits
mailing list