From 5b153bbd63d067e9f6d93ad6caef18d9d2e64071 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 8 Jan 2014 15:59:42 +0000 Subject: [PATCH] clang-format: Don't hang forever when encountering a stray "}" in an @implementation block. PR18406. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198770 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/UnwrappedLineParser.cpp | 4 ++++ unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 0087e5eabe..ec7c5dd0ee 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1255,6 +1255,10 @@ void UnwrappedLineParser::parseObjCUntilAtEnd() { parseBlock(/*MustBeDeclaration=*/false); // In ObjC interfaces, nothing should be following the "}". addUnwrappedLine(); + } else if (FormatTok->is(tok::r_brace)) { + // Ignore stray "}". parseStructuralElement doesn't consume them. + nextToken(); + addUnwrappedLine(); } else { parseStructuralElement(); } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 756c71cf3c..ea215ab757 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5596,6 +5596,10 @@ TEST_F(FormatTest, FormatObjCProtocol) { " int *looooooooooooooooooooooooooooongNumber;\n" "@property(nonatomic, assign, readonly)\n" " NSString *looooooooooooooooooooooooooooongName;"); + + verifyFormat("@implementation PR18406\n" + "}\n" + "@end"); } TEST_F(FormatTest, FormatObjCMethodDeclarations) { -- 2.40.0