[clang-format] Wrap inserted braces only if preceded by comments

Fixes #57805.

Differential Revision: https://reviews.llvm.org/D134233
This commit is contained in:
owenca
2022-09-19 15:28:18 -07:00
parent 68cc35d52c
commit 6257832bf9
2 changed files with 7 additions and 1 deletions

View File

@@ -1871,7 +1871,7 @@ private:
std::string Brace;
if (Token->BraceCount < 0) {
assert(Token->BraceCount == -1);
Brace = "\n{";
Brace = Token->is(tok::comment) ? "\n{" : "{";
} else {
Brace = '\n' + std::string(Token->BraceCount, '}');
}

View File

@@ -25388,6 +25388,12 @@ TEST_F(FormatTest, InsertBraces) {
"} while (0);",
Style);
Style.RemoveBracesLLVM = true;
verifyFormat("if (a) //\n"
" return b;",
Style);
Style.RemoveBracesLLVM = false;
Style.ColumnLimit = 15;
verifyFormat("#define A \\\n"