Skip to content

Commit e3713f1

Browse files
committed
[clang-format] Avoid considering include directive as a template closer.
This fixes a bug [[ http://llvm.org/PR48891 | PR48891 ]] introduced in D93839 where: ``` #include <stdint.h> namespace rep {} ``` got formatted as ``` #include <stdint.h> namespace rep { } ``` Reviewed By: MyDeveloperDay, leonardchan Differential Revision: https://reviews.llvm.org/D95479
1 parent b6d87e6 commit e3713f1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class LineJoiner {
371371
if (Previous->is(tok::comment))
372372
Previous = Previous->getPreviousNonComment();
373373
if (Previous) {
374-
if (Previous->is(tok::greater))
374+
if (Previous->is(tok::greater) && !I[-1]->InPPDirective)
375375
return 0;
376376
if (Previous->is(tok::identifier)) {
377377
const FormatToken *PreviousPrevious =

clang/unittests/Format/FormatTest.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10248,6 +10248,21 @@ TEST_F(FormatTest, SplitEmptyClass) {
1024810248
"{\n"
1024910249
"};",
1025010250
Style);
10251+
10252+
verifyFormat("#include \"stdint.h\"\n"
10253+
"namespace rep {}",
10254+
Style);
10255+
verifyFormat("#include <stdint.h>\n"
10256+
"namespace rep {}",
10257+
Style);
10258+
verifyFormat("#include <stdint.h>\n"
10259+
"namespace rep {}",
10260+
"#include <stdint.h>\n"
10261+
"namespace rep {\n"
10262+
"\n"
10263+
"\n"
10264+
"}",
10265+
Style);
1025110266
}
1025210267

1025310268
TEST_F(FormatTest, SplitEmptyStruct) {

0 commit comments

Comments
 (0)