diff options
author | Mitchell Balan <mitchell@stellarscience.com> | 2020-01-06 09:21:41 -0500 |
---|---|---|
committer | Mitchell Balan <mitchell@stellarscience.com> | 2020-01-06 09:21:41 -0500 |
commit | d45aafa2fbcf66f3dafdc7c5e0a0ce3709914cbc (patch) | |
tree | afa25c852bd5b4db55025aaa116b9f027ee4764d /clang/lib | |
parent | de735247c8b638efa8ce5783ac8c7c2e0b7cf3eb (diff) | |
download | bcm5719-llvm-d45aafa2fbcf66f3dafdc7c5e0a0ce3709914cbc.tar.gz bcm5719-llvm-d45aafa2fbcf66f3dafdc7c5e0a0ce3709914cbc.zip |
[clang-format] fix conflict between FormatStyle::BWACS_MultiLine and BeforeCatch/BeforeElse
Summary:
Found a bug introduced with BraceWrappingFlags AfterControlStatement MultiLine. This feature conflicts with the existing BeforeCatch and BeforeElse flags.
For example, our team uses BeforeElse.
if (foo ||
bar) {
doSomething();
}
else {
doSomethingElse();
}
If we enable MultiLine (which we'd really love to do) we expect it to work like this:
if (foo ||
bar)
{
doSomething();
}
else {
doSomethingElse();
}
What we actually get is:
if (foo ||
bar)
{
doSomething();
}
else
{
doSomethingElse();
}
Reviewers: MyDeveloperDay, Bouska, mitchell-stellar
Patch by: pastey
Subscribers: Bouska, cfe-commits
Tags: clang
Differential Revision: https://reviews.llvm.org/D71939
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Format/UnwrappedLineFormatter.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 8b8d357d9cb..fec85f1174d 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -326,6 +326,19 @@ private: FormatStyle::BWACS_Always) ? tryMergeSimpleBlock(I, E, Limit) : 0; + } else if (I[1]->First->is(tok::l_brace) && + TheLine->First->isOneOf(tok::kw_else, tok::kw_catch) && + Style.BraceWrapping.AfterControlStatement == + FormatStyle::BWACS_MultiLine) { + // This case if different from the upper BWACS_MultiLine processing + // in that a preceding r_brace is not on the same line as else/catch + // most likely because of BeforeElse/BeforeCatch set to true. + // If the line length doesn't fit ColumnLimit, leave l_brace on the + // next line to respect the BWACS_MultiLine. + return (Style.ColumnLimit == 0 || + TheLine->Last->TotalLength <= Style.ColumnLimit) + ? 1 + : 0; } // Try to merge either empty or one-line block if is precedeed by control // statement token |