[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
This commit is contained in:
Marek Kurdej 2021-01-27 09:14:22 +01:00
parent b6d87e6a92
commit e3713f156b
2 changed files with 16 additions and 1 deletions

View File

@ -371,7 +371,7 @@ private:
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 =

View File

@ -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) {