New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-format] AlignAfterOpenBracket = BlockIndent
doesn't affect braced lists when Cpp11BracedListStyle = true
#57878
Comments
@llvm/issue-subscribers-clang-format |
@jgcodes2020 this example uses a C89-style array initializer and not a C++11 braced list. I'm not sure this is valid. I will however note that I think this is a real bug with the following example:
being formatted as
with the command: I don't know that there's any way currently to achieve the style given in your example. |
The following patch works for me, but I didn't test extensively. diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index f9f0d712b..f46e05b7c 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -84,7 +84,9 @@ bool FormatToken::opensBlockOrBlockTypeList(const FormatStyle &Style) const {
return is(TT_ArrayInitializerLSquare) || is(TT_ProtoExtensionLSquare) ||
(is(tok::l_brace) &&
(getBlockKind() == BK_Block || is(TT_DictLiteral) ||
- (!Style.Cpp11BracedListStyle && NestingLevel == 0))) ||
+ ((!Style.Cpp11BracedListStyle ||
+ Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) &&
+ NestingLevel == 0))) ||
(is(tok::less) && (Style.Language == FormatStyle::LK_Proto ||
Style.Language == FormatStyle::LK_TextProto));
} |
That patch doesn't work right. It makes the braced initializers act like blocks, and indents based on llvm-project/clang/lib/Format/TokenAnnotator.cpp Line 5313 in 1797ab3
This in part seems to cause the first comment inside of { ... } identified as a braced list to be consumed/aligned according to the rules associated with the first element of the braced list. From what I can tell, that behavior is not desired for = { ... } code. So it requires some care to separate these cases.
Furthermore, how this should interact with the array of structure initializers ( |
I have submitted https://reviews.llvm.org/D153205 that adds this support. |
|
However clang-format will treat braces as parentheses when
|
Description
The documentation states the following:
When setting
AlignAfterOpenBracket = BlockIndent
, functions that can't fit on one line become:my_function( my_long_parameter_1, my_long_parameter_2, my_long_parameter_3, my_long_parameter_4, );
If the documentation is actually correct, then setting
Cpp11BracedListStyle = true
should make braced lists look like:Instead, it does this:
Specs
The text was updated successfully, but these errors were encountered: