-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang-format] AlignAfterOpenBracket: BlockIndent
produces inconsistent/bad formatting
#55731
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
Comments
@llvm/issue-subscribers-clang-format |
Not sure if related, but there seems to be some strange interaction between using
with the settings shown above this gets turned into
which is ok. Now I want 2 spaces for indent so change
now change
|
Since it seems this is now the chosen issue for tracking this bug, #54808 could be closed as another duplicate. |
A simple version of the problem might help:
Before:
After:
I've tried reducing the .clang-format:
|
Your examples could also be expanded by placing a single parameter on a line:
|
This is a separate, but related issue i.e. Expanded examples:
For comparison it works as expected with
|
Any updates on this? Here is how void Workshop02::run()
{
ANNOUNCE_WORKSHOP("Workshop 02: Uninitialized Variables & Undefined Behavior"
);
int x;
std::cout << "Uninitialized variable x: " << x << '\n';
std::cout << "Size of an int: " << sizeof(int) << '\n';
} Expected result: void Workshop02::run()
{
ANNOUNCE_WORKSHOP(
"Workshop 02: Uninitialized Variables & Undefined Behavior"
);
int x;
std::cout << "Uninitialized variable x: " << x << '\n';
std::cout << "Size of an int: " << sizeof(int) << '\n';
} |
Please retry with |
Fixes llvm#55731 Fixes llvm#73584 The reported formatting problems were related to ignoring deep nesting of "simple" functions (causing llvm#54808) and to allowing the trailing annotation to become separated from the closing parens, which allowed a break to occur between the closing parens and the trailing annotation. The fix for the nesting of "simple" functions is to detect them more carefully. "Simple" was defined in a comment as being a single non-expression argument. I tried to stay as close to the original intent of the implementation while fixing the various bad formatting reports. In the process of fixing these bugs, some latent bugs were discovered related to how JavaScript Template Strings are handled. Those are also fixed here.
That works. 😄 So it's still just the
|
Fixes llvm#55731 Fixes llvm#73584 The reported formatting problems were related to ignoring deep nesting of "simple" functions (causing llvm#54808) and to allowing the trailing annotation to become separated from the closing parens, which allowed a break to occur between the closing parens and the trailing annotation. The fix for the nesting of "simple" functions is to detect them more carefully. "Simple" was defined in a comment as being a single non-expression argument. I tried to stay as close to the original intent of the implementation while fixing the various bad formatting reports. In the process of fixing these bugs, some latent bugs were discovered related to how JavaScript Template Strings are handled. Those are also fixed here.
Fixes llvm#55731 Fixes llvm#73584 The reported formatting problems were related to ignoring deep nesting of "simple" functions (causing llvm#54808) and to allowing the trailing annotation to become separated from the closing parens, which allowed a break to occur between the closing parens and the trailing annotation. The fix for the nesting of "simple" functions is to detect them more carefully. "Simple" was defined in a comment as being a single non-expression argument. I tried to stay as close to the original intent of the implementation while fixing the various bad formatting reports. In the process of fixing these bugs, some latent bugs were discovered related to how JavaScript Template Strings are handled. Those are also fixed here.
Summary: Fixes #55731 The reported formatting problems were related to ignoring deep nesting of "simple" functions (causing #54808) and to allowing the trailing annotation to become separated from the closing parens, which allowed a break to occur between the closing parens and the trailing annotation. The fix for the nesting of "simple" functions is to detect them more carefully. "Simple" was defined in a comment as being a single non-expression argument. I tried to stay as close to the original intent of the implementation while fixing the various bad formatting reports. In the process of fixing these bugs, some latent bugs were discovered related to how JavaScript Template Strings are handled. Those are also fixed here. --------- Co-authored-by: Owen Pan <[email protected]> Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250557
My
.clang-format
file looks like:The result looks like:
I would expect something like:
If a function declaration cannot fit on a single line it should preferably be broken after the opening and closing bracket always.
I love this new option but it needs work for braces
{}
and brackets()
, etc.References:
The text was updated successfully, but these errors were encountered: