зеркало из https://github.com/microsoft/clang-1.git
Fixed handling of comments before preprocessor directives.
Comments before preprocessor directives used to be stored with InPPDirective flag set, which prevented correct comment splitting in this case. Fixed by flushing comments before switching on InPPDirective. Added a new test and fixed one of the existing tests. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178261 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
03852c8717
Коммит
9fdc00a237
|
@ -822,6 +822,7 @@ void UnwrappedLineParser::readToken() {
|
||||||
while (!Line->InPPDirective && FormatTok.Tok.is(tok::hash) &&
|
while (!Line->InPPDirective && FormatTok.Tok.is(tok::hash) &&
|
||||||
((FormatTok.NewlinesBefore > 0 && FormatTok.HasUnescapedNewline) ||
|
((FormatTok.NewlinesBefore > 0 && FormatTok.HasUnescapedNewline) ||
|
||||||
FormatTok.IsFirst)) {
|
FormatTok.IsFirst)) {
|
||||||
|
flushComments(FormatTok.NewlinesBefore > 0);
|
||||||
// If there is an unfinished unwrapped line, we flush the preprocessor
|
// If there is an unfinished unwrapped line, we flush the preprocessor
|
||||||
// directives only after that unwrapped line was finished later.
|
// directives only after that unwrapped line was finished later.
|
||||||
bool SwitchToPreprocessorLines =
|
bool SwitchToPreprocessorLines =
|
||||||
|
|
|
@ -699,6 +699,13 @@ TEST_F(FormatTest, SplitsLongCxxComments) {
|
||||||
"//Don't add leading\n"
|
"//Don't add leading\n"
|
||||||
"//whitespace",
|
"//whitespace",
|
||||||
format("//Don't add leading whitespace", getLLVMStyleWithColumns(20)));
|
format("//Don't add leading whitespace", getLLVMStyleWithColumns(20)));
|
||||||
|
EXPECT_EQ("// A comment before\n"
|
||||||
|
"// a macro\n"
|
||||||
|
"// definition\n"
|
||||||
|
"#define a b",
|
||||||
|
format("// A comment before a macro definition\n"
|
||||||
|
"#define a b",
|
||||||
|
getLLVMStyleWithColumns(20)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatTest, SplitsLongLinesInComments) {
|
TEST_F(FormatTest, SplitsLongLinesInComments) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче