summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-04-30 09:24:17 +0000
committerDaniel Jasper <djasper@google.com>2015-04-30 09:24:17 +0000
commite9f5357f495dabedcc84bd956da7c357d8547fd1 (patch)
treea55f776bb37a175175862e7c352159499eb5662e /clang/lib/Format
parent90b059d555e7e3a910dad247a342babb537d5cd7 (diff)
downloadbcm5719-llvm-e9f5357f495dabedcc84bd956da7c357d8547fd1.tar.gz
bcm5719-llvm-e9f5357f495dabedcc84bd956da7c357d8547fd1.zip
clang-format: Don't merge short else blocks.
Before (with the appropriate flags settings): if (a) { f(); } else { g(); } Before (with other appropriate flags settings): if (a) { f(); } else { g(); } After: if (a) { f(); } else { g(); } llvm-svn: 236217
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index dd65230cc40..888c69176ec 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -203,7 +203,8 @@ 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))
+ if (Line.First->isOneOf(tok::kw_else, tok::kw_case) ||
+ (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,
@@ -264,6 +265,10 @@ private:
if (Tok->isNot(tok::r_brace))
return 0;
+ // Don't merge "if (a) { .. } else {".
+ if (Tok->Next && Tok->Next->is(tok::kw_else))
+ return 0;
+
return 2;
}
return 0;
OpenPOWER on IntegriCloud