r226447 - clang-format: Fix endless loop on incomplete try-catch-block.

Daniel Jasper djasper at google.com
Mon Jan 19 02:50:51 PST 2015


Author: djasper
Date: Mon Jan 19 04:50:51 2015
New Revision: 226447

URL: http://llvm.org/viewvc/llvm-project?rev=226447&view=rev
Log:
clang-format: Fix endless loop on incomplete try-catch-block.

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=226447&r1=226446&r2=226447&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Jan 19 04:50:51 2015
@@ -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();
     }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=226447&r1=226446&r2=226447&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 19 04:50:51 2015
@@ -2230,6 +2230,9 @@ TEST_F(FormatTest, FormatTryCatch) {
                "    throw;\n"
                "  }\n"
                "};\n");
+
+  // Incomplete try-catch blocks.
+  verifyFormat("try {} catch (");
 }
 
 TEST_F(FormatTest, IncompleteTryCatchBlocks) {





More information about the cfe-commits mailing list