owenpan created this revision. owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, curdeius. owenpan added a project: clang-format. Herald added a project: All. owenpan requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Fixes https://github.com/llvm/llvm-project/issues/57805. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D134233 Files: clang/lib/Format/Format.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -25388,6 +25388,12 @@ "} while (0);", Style); + Style.RemoveBracesLLVM = true; + verifyFormat("if (a) //\n" + " return b;", + Style); + Style.RemoveBracesLLVM = false; + Style.ColumnLimit = 15; verifyFormat("#define A \\\n" Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1871,7 +1871,7 @@ 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, '}'); }
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -25388,6 +25388,12 @@ "} while (0);", Style); + Style.RemoveBracesLLVM = true; + verifyFormat("if (a) //\n" + " return b;", + Style); + Style.RemoveBracesLLVM = false; + Style.ColumnLimit = 15; verifyFormat("#define A \\\n" Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1871,7 +1871,7 @@ 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, '}'); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits