This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGc05da55bdf54: [clang-format] Handle trailing comment for InsertBraces (authored by owenpan).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D120503/new/ https://reviews.llvm.org/D120503 Files: clang/lib/Format/Format.cpp clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -24481,6 +24481,13 @@ " f();", Style); + verifyFormat("if (a) {\n" + " f(); // comment\n" + "}", + "if (a)\n" + " f(); // comment", + Style); + verifyFormat("if (a) {\n" " f();\n" "}\n" Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2336,10 +2336,9 @@ assert(!Line->InPPDirective); Tok = nullptr; for (const auto &L : llvm::reverse(*CurrentLines)) { - if (!L.InPPDirective) { - Tok = getLastNonComment(L); - if (Tok) - break; + if (!L.InPPDirective && getLastNonComment(L)) { + Tok = L.Tokens.back().Tok; + break; } } assert(Tok); Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1855,7 +1855,7 @@ assert(Token->BraceCount == -1); Brace = '{'; } else { - Brace = std::string(Token->BraceCount, '}'); + Brace = '\n' + std::string(Token->BraceCount, '}'); } Token->BraceCount = 0; const auto Start = Token->Tok.getEndLoc();
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -24481,6 +24481,13 @@ " f();", Style); + verifyFormat("if (a) {\n" + " f(); // comment\n" + "}", + "if (a)\n" + " f(); // comment", + Style); + verifyFormat("if (a) {\n" " f();\n" "}\n" Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2336,10 +2336,9 @@ assert(!Line->InPPDirective); Tok = nullptr; for (const auto &L : llvm::reverse(*CurrentLines)) { - if (!L.InPPDirective) { - Tok = getLastNonComment(L); - if (Tok) - break; + if (!L.InPPDirective && getLastNonComment(L)) { + Tok = L.Tokens.back().Tok; + break; } } assert(Tok); Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1855,7 +1855,7 @@ assert(Token->BraceCount == -1); Brace = '{'; } else { - Brace = std::string(Token->BraceCount, '}'); + Brace = '\n' + std::string(Token->BraceCount, '}'); } Token->BraceCount = 0; const auto Start = Token->Tok.getEndLoc();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits