forked from OSchip/llvm-project
Comments should not prevent single-line functions.
Before: void f() {} void g() { } // comment After: void f() {} void g() {} // comment llvm-svn: 181996
This commit is contained in:
parent
950f318ff1
commit
f9eb9b1883
|
@ -1418,7 +1418,7 @@ private:
|
|||
return;
|
||||
|
||||
AnnotatedToken *Tok = &(I + 1)->First;
|
||||
if (Tok->Children.empty() && Tok->is(tok::r_brace) &&
|
||||
if (Tok->getNextNoneComment() == NULL && Tok->is(tok::r_brace) &&
|
||||
!Tok->MustBreakBefore) {
|
||||
// We merge empty blocks even if the line exceeds the column limit.
|
||||
Tok->SpacesRequiredBefore = 0;
|
||||
|
@ -1443,7 +1443,7 @@ private:
|
|||
|
||||
// Last, check that the third line contains a single closing brace.
|
||||
Tok = &(I + 2)->First;
|
||||
if (!Tok->Children.empty() || Tok->isNot(tok::r_brace) ||
|
||||
if (Tok->getNextNoneComment() != NULL || Tok->isNot(tok::r_brace) ||
|
||||
Tok->MustBreakBefore)
|
||||
return;
|
||||
|
||||
|
|
|
@ -3043,6 +3043,8 @@ TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {
|
|||
" int a;\n"
|
||||
"#error {\n"
|
||||
"}");
|
||||
verifyFormat("void f() {} // comment");
|
||||
verifyFormat("void f() { int a; } // comment");
|
||||
|
||||
verifyFormat("void f() { return 42; }", getLLVMStyleWithColumns(23));
|
||||
verifyFormat("void f() {\n return 42;\n}", getLLVMStyleWithColumns(22));
|
||||
|
|
Loading…
Reference in New Issue