Skip to content

Commit

Permalink
[clang-format] Avoid considering include directive as a template closer.
Browse files Browse the repository at this point in the history
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

(cherry picked from commit e3713f1)
  • Loading branch information
mkurdej authored and tstellar committed Jan 30, 2021
1 parent de3396d commit 0a32d93
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Format/UnwrappedLineFormatter.cpp
Expand Up @@ -371,7 +371,7 @@ class LineJoiner {
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 =
Expand Down
15 changes: 15 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Expand Up @@ -10248,6 +10248,21 @@ TEST_F(FormatTest, SplitEmptyClass) {
"{\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) {
Expand Down

0 comments on commit 0a32d93

Please sign in to comment.