From: Daniel Jasper Date: Mon, 19 Jan 2015 10:50:51 +0000 (+0000) Subject: clang-format: Fix endless loop on incomplete try-catch-block. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7a1e6b7b2d5a5e77f8b6330211fccec1ad7b2d55;p=clang clang-format: Fix endless loop on incomplete try-catch-block. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226447 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index ec04af5231..00dc1bda53 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1198,7 +1198,7 @@ void UnwrappedLineParser::parseTryCatch() { parseParens(); continue; } - if (FormatTok->isOneOf(tok::semi, tok::r_brace)) + if (FormatTok->isOneOf(tok::semi, tok::r_brace, tok::eof)) return; nextToken(); } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index e1484b7239..5f8fba26e5 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2230,6 +2230,9 @@ TEST_F(FormatTest, FormatTryCatch) { " throw;\n" " }\n" "};\n"); + + // Incomplete try-catch blocks. + verifyFormat("try {} catch ("); } TEST_F(FormatTest, IncompleteTryCatchBlocks) {