[PATCH] D12492: [Clang-Format] Add AlwaysBreakBeforeElse and AlwaysBreakBeforeCatch Style to avoid cuddled else/catch
Paul Hoad via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 17 02:50:11 PDT 2015
MyDeveloperDay added inline comments.
================
Comment at: docs/ClangFormatStyleOptions.rst:247
@@ -246,1 +246,3 @@
+**AlwaysBreakBeforeElse** (``bool``)
+ If ``true``, always break before ``else``.
----------------
djasper wrote:
> Hm, I think these should be grouped in some way and interact with BreakBeforeBraces.
>
> I theory, I'd like to have a lot of different flags and make BreakBeforeBraces select specific presents for them. However, maybe we can put all the brace breaking options together in some nice way (don't have a very good idea yet).
>
> Not saying that you need to do all of this, but pulling these two options out from the other BreakBeforeBraces options seems a little undesirable. They essentially also just define what we do around braces.
Well I agree, ideally the BreakBeforeBraces styles should be implemented by setting the finite control on each element
Then code like this
if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
Style.BreakBeforeBraces == FormatStyle::BS_GNU ||
Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup ||
Style.AlwaysBreakBeforeCatch) {
...
}
could become
if (Style.AlwaysBreakBeforeCatch) {
...
}
This would simply require some code in the initializer that says
if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
Style.BreakBeforeBraces == FormatStyle::BS_GNU ||
Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup)
{
Style.AlwaysBreakBeforeCatch=true;
}
if (Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup)
{
Style.AlwaysBreakBeforeElse=true;
}
This would allow those of us not using one of the 5 chosen styles to build our teams style guide via the individual capabilities
Removing all the BS_Stroustrup/Allman etc.. from the UnwrappedLineParser will greatly improve its readability
http://reviews.llvm.org/D12492
More information about the cfe-commits
mailing list