This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG6cd9633c1da5: [clang-format] Handle comments below r_brace in RemoveBracesLLVM (authored by owenpan).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125451/new/ https://reviews.llvm.org/D125451 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 @@ -25348,6 +25348,20 @@ "}", Style); + verifyFormat("if (a)\n" + " foo();\n" + "// comment\n" + "else\n" + " bar();", + "if (a) {\n" + " foo();\n" + "}\n" + "// comment\n" + "else {\n" + " bar();\n" + "}", + Style); + verifyFormat("if (a) {\n" "Label:\n" "}", Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1898,8 +1898,9 @@ assert(Token->isOneOf(tok::l_brace, tok::r_brace)); assert(Token->Next || Token == Line->Last); const auto Start = - Token == Line->Last || (Token->Next->is(tok::kw_else) && - Token->Next->NewlinesBefore > 0) + Token == Line->Last || + (Token->Next->isOneOf(tok::kw_else, tok::comment) && + Token->Next->NewlinesBefore > 0) ? Token->WhitespaceRange.getBegin() : Token->Tok.getLocation(); const auto Range =
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -25348,6 +25348,20 @@ "}", Style); + verifyFormat("if (a)\n" + " foo();\n" + "// comment\n" + "else\n" + " bar();", + "if (a) {\n" + " foo();\n" + "}\n" + "// comment\n" + "else {\n" + " bar();\n" + "}", + Style); + verifyFormat("if (a) {\n" "Label:\n" "}", Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1898,8 +1898,9 @@ assert(Token->isOneOf(tok::l_brace, tok::r_brace)); assert(Token->Next || Token == Line->Last); const auto Start = - Token == Line->Last || (Token->Next->is(tok::kw_else) && - Token->Next->NewlinesBefore > 0) + Token == Line->Last || + (Token->Next->isOneOf(tok::kw_else, tok::comment) && + Token->Next->NewlinesBefore > 0) ? Token->WhitespaceRange.getBegin() : Token->Tok.getLocation(); const auto Range =
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits