-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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-18 Comments alligned across scopes #67906
Comments
Bisected to 77a38f4. @HazardyKnusperkeks can you have a look? |
But is this wrong? |
Usually you want to align comments because they are related to the same
context (a class, a function, a struct), alligning those across context
seems wrong. Also if instead of a function you do the same with a namespace
then the alignment doesn't happen. So one of the two is wrong.
Gaetano
…On Wed, Oct 4, 2023, 21:17 Björn Schäpers ***@***.***> wrote:
But is this wrong?
The documentation states TCAS_Always (in configuration: Always) Align
trailing comments. There is no limitation of a scope.
@kalman5 <https://github.com/kalman5> why do you think it shouldn't be
aligned? (Apart from that we didn't to that in the past.)
—
Reply to this email directly, view it on GitHub
<#67906 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAPIUZN3T34L3T5R5RBFMUDX5WY23AVCNFSM6AAAAAA5OEASRKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONBXGQ4TENZVGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Do you refer that comments on closing namespace braces are not aligned? Yes that's the case now. Before that commit all comments on braces which are the first character on a line would not be aligned, but on all other closing braces they would be, even namespace braces. There was no concept of scope involved. class C {
void foo() {
#if 1 // reference
#elif 0 // slower
#else // slowest
#endif // 0
} // foo
}; // bar Of course we could expand the non alignment to all closing braces. And we should, regardless adapt the documentation of |
Exactly! I prefer the clang-17 behavior on this.
…On Thu, Oct 5, 2023, 21:29 Björn Schäpers ***@***.***> wrote:
Also if instead of a function you do the same with a namespace then the
alignment doesn't happen.
Do you refer that comments on closing namespace braces are not aligned?
Yes that's the case now. Before that commit all comments on braces which
are the first character on a line would not be aligned, but on all other
closing braces they would be, even namespace braces. There was no concept
of scope involved.
What does clang-format 17 do with:
class C {
void foo() {
#if 1 // reference
#elif 0 // slower
#else // slowest#endif // 0
} // foo
}; // bar
Of course we could expand the non alignment to all closing braces.
And we should, regardless adapt the documentation of AlignTrailingComments
.
—
Reply to this email directly, view it on GitHub
<#67906 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAPIUZJZ3WDCW3R2RMQ7E4DX54DA3AVCNFSM6AAAAAA5OEASRKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONBZGUYTSNZXGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
That was a question, I thought you ran it through. Based on your answer you may be surprised on the actual formatting. $ echo -e "class C{void foo(){\n#if 1//ref\n#elif 0//sl\n#else//slow\n#endif//0\n}//foo\n};//bar" | clang-format
class C {
void foo() {
#if 1 // ref
#elif 0 // sl
#else // slow
#endif // 0
} // foo
}; // bar So I open the question to @rymiel @owenca and @mydeveloperday:
I'm in favor of 4 or 3. |
It seems that clang-format version 18 is more consistent than 17:
However, IMO it doesn't make sense to align comments across scopes. Instead, the expected output should be:
|
Both versions 17 and 18 format it as:
Again, IMO the closing brace comments should not be aligned. |
In preparation of llvm#67906.
In preparation of llvm#67906.
A tentative fix is in the pull request, a few points are still open for debate. |
Annotating switch braces for the first time. Extract the type setting into its own function. Also in preparation of llvm#67906.
Annotating switch braces for the first time. Also in preparation of #67906.
I think something as simple as "not aligning trailing comments preceded by a wrapped group of 1 or more closing braces optionally followed by a semicolon" would suffice. For example:
|
To clarify, by "closing braces" I meant any types of braces including braces of |
That should be in the newest version. (There are no tests for try, etc. I'll add them.) |
We now stop aligning trailing comments on all closing braces, for classes etc. we even check for the semicolon between the comment and the brace. Fixes llvm#67906.
We now stop aligning trailing comments on all closing braces, for classes etc. we even check for the semicolon between the comment and the brace. Fixes #67906.
The following snippet
formattted with clang-format-17 using the following configuration
is formatted in the following way using clang-format-18
as you can see the comment at the end foo is alligned with other comments inside another scope
The text was updated successfully, but these errors were encountered: