Author: owenca Date: 2022-05-21T10:33:59-07:00 New Revision: 8bfccb963b3519393c0266b452a115a4bb46d207
URL: https://github.com/llvm/llvm-project/commit/8bfccb963b3519393c0266b452a115a4bb46d207 DIFF: https://github.com/llvm/llvm-project/commit/8bfccb963b3519393c0266b452a115a4bb46d207.diff LOG: [clang-format] Fix an infinite loop in parseJavaEnumBody() Fixes #55623. Added: Modified: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTestJava.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index be081a9189600..18f476aca01ae 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -3509,7 +3509,7 @@ void UnwrappedLineParser::parseJavaEnumBody() { ++Line->Level; // Parse the enum constants. - while (FormatTok) { + while (FormatTok->isNot(tok::eof)) { if (FormatTok->is(tok::l_brace)) { // Parse the constant's class body. parseBlock(/*MustBeDeclaration=*/true, /*AddLevels=*/1u, diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index e778836e0fc9a..03e16ae0a00d3 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -197,6 +197,8 @@ TEST_F(FormatTestJava, EnumDeclarations) { " CDE;\n" " void f() {}\n" "}"); + verifyFormat("enum SomeThing {\n" + " void f() {}"); verifyFormat("enum SomeThing {\n" " ABC(1, \"ABC\"),\n" " CDE(2, \"CDE\");\n" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits