Author: Sam McCall Date: 2022-11-24T15:14:06+01:00 New Revision: a72609cabef4c5f5afa3811575a3963830cb13dd
URL: https://github.com/llvm/llvm-project/commit/a72609cabef4c5f5afa3811575a3963830cb13dd DIFF: https://github.com/llvm/llvm-project/commit/a72609cabef4c5f5afa3811575a3963830cb13dd.diff LOG: [Format] Don't crash on mismatched brackets Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTestCSharp.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 7f16d04d898b9..889dfa5fd7a63 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2837,7 +2837,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current, if (!Current.is(TT_StartOfName) || Current.NestingLevel != 0) return false; for (; Next; Next = Next->Next) { - if (Next->is(TT_TemplateOpener)) { + if (Next->is(TT_TemplateOpener) && Next->MatchingParen) { Next = Next->MatchingParen; } else if (Next->is(tok::coloncolon)) { Next = Next->Next; diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index a18f57ec57144..1928a0d2da632 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -1600,5 +1600,9 @@ TEST_F(FormatTestCSharp, ShortFunctions) { Style); } +TEST_F(FormatTestCSharp, BrokenBrackets) { + EXPECT_NE("", format("int where b <")); // reduced from crasher +} + } // namespace format } // end namespace clang _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits