owenpan created this revision. owenpan added reviewers: HazardyKnusperkeks, curdeius, MyDeveloperDay. 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/54384. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D121682 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -12089,6 +12089,7 @@ verifyFormat("if {\n foo;\n foo();\n}"); verifyFormat("switch {\n foo;\n foo();\n}"); verifyIncompleteFormat("for {\n foo;\n foo();\n}"); + verifyIncompleteFormat("ERROR: for target;"); verifyFormat("while {\n foo;\n foo();\n}"); verifyFormat("do {\n foo;\n foo();\n} while;"); } Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1023,6 +1023,8 @@ if (Style.isCpp() && CurrentToken && CurrentToken->is(tok::kw_co_await)) next(); Contexts.back().ColonIsForRangeExpr = true; + if (!CurrentToken || CurrentToken->isNot(tok::l_paren)) + return false; next(); if (!parseParens()) return false;
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -12089,6 +12089,7 @@ verifyFormat("if {\n foo;\n foo();\n}"); verifyFormat("switch {\n foo;\n foo();\n}"); verifyIncompleteFormat("for {\n foo;\n foo();\n}"); + verifyIncompleteFormat("ERROR: for target;"); verifyFormat("while {\n foo;\n foo();\n}"); verifyFormat("do {\n foo;\n foo();\n} while;"); } Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1023,6 +1023,8 @@ if (Style.isCpp() && CurrentToken && CurrentToken->is(tok::kw_co_await)) next(); Contexts.back().ColonIsForRangeExpr = true; + if (!CurrentToken || CurrentToken->isNot(tok::l_paren)) + return false; next(); if (!parseParens()) return false;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits