[clang] 8bfccb9 - [clang-format] Fix an infinite loop in parseJavaEnumBody()
via cfe-commits
cfe-commits at lists.llvm.org
Sat May 21 10:34:34 PDT 2022
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"
More information about the cfe-commits
mailing list