From 4e0b56c202361f464daadc14e860a7842f7edbb2 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Mon, 2 Oct 2017 15:53:37 +0000 Subject: [clang-format] Fix regression about short functions after #else Summary: This patch fixes a regression introduced in r312904, where the formatter confuses the `else` in `#else` with an `else` of an `if-else` statement. For example, formatting this code with google style ``` #ifdef A int f() {} #else int f() {} #endif ``` resulted in ``` #ifdef A int f() {} #else int f() { } #endif ``` Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D37973 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314683 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/UnwrappedLineFormatter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/Format') diff --git a/lib/Format/UnwrappedLineFormatter.cpp b/lib/Format/UnwrappedLineFormatter.cpp index 6c75adaddc..d25f0a1c29 100644 --- a/lib/Format/UnwrappedLineFormatter.cpp +++ b/lib/Format/UnwrappedLineFormatter.cpp @@ -466,8 +466,7 @@ private: // Check that the current line allows merging. This depends on whether we // are in a control flow statements as well as several style flags. if (Line.First->isOneOf(tok::kw_else, tok::kw_case) || - (Line.First->Next && Line.First->Next->is(tok::kw_else)) || - (I != AnnotatedLines.begin() && I[-1]->Last->is(tok::kw_else))) + (Line.First->Next && Line.First->Next->is(tok::kw_else))) return 0; if (Line.First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::kw_try, tok::kw___try, tok::kw_catch, tok::kw___finally, -- cgit v1.2.3