From: Daniel Jasper Date: Sat, 12 Oct 2013 13:32:56 +0000 (+0000) Subject: clang-format: Fix assertion on unterminated #ifs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ac4d0181928e3e22fa3929ca1b24ae7f14fb7628;p=clang clang-format: Fix assertion on unterminated #ifs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192535 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 93840dcad8..e8503bb332 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -225,7 +225,7 @@ bool UnwrappedLineParser::parse() { Callback.finishRun(); Lines.clear(); while (!PPLevelBranchIndex.empty() && - PPLevelBranchIndex.back() + 1 == PPLevelBranchCount.back()) { + PPLevelBranchIndex.back() + 1 >= PPLevelBranchCount.back()) { PPLevelBranchIndex.resize(PPLevelBranchIndex.size() - 1); PPLevelBranchCount.resize(PPLevelBranchCount.size() - 1); } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 5fea8e781e..6e8179a306 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2317,6 +2317,8 @@ TEST_F(FormatTest, LayoutStatementsAroundPreprocessorDirectives) { " x();\n" "}", getLLVMStyleWithColumns(28)); + verifyFormat("#if 1\n" + "int i;"); } TEST_F(FormatTest, LayoutBlockInsideParens) {