Fixes https://github.com/llvm/llvm-project/issues/31568.
Added a check for operator keyword tokens.
Paths
| Differential D117421
[clang-format] Fix incorrect alignment of operator= overloads. ClosedPublic Authored by glotchimo on Jan 16 2022, 12:36 AM.
Details Summary Fixes https://github.com/llvm/llvm-project/issues/31568. Added a check for operator keyword tokens.
Diff Detail
Unit TestsFailed Event TimelineComment Actions I don't know why, but clang-format reformatted most if not all of the long/block comments in WhitespaceManager.cpp. Will it be necessary for me to revert the changes to those comments and skip formatting when updating the diff so as to keep it minimal? curdeius retitled this revision from Fix 31568 (i.e. incorrect alignment of operator= overloads). to [clang-format] Fix incorrect alignment of operator= overloads..Jan 16 2022, 10:00 AM Comment Actions Thanks for working on this!
Comment Actions Thanks for fixing this. It hit my quite some times, but never had the time to look into it. Comment Actions Could you check if your patch fixes https://github.com/llvm/llvm-project/issues/33044 as well? Comment Actions
If when editing you save (and clang-format) when you've missed a } then the file likely reindented, this, in turn, reflowed the comments, which means when you add the '}' back in, those comments have newlines in different places once reflowed the comments don't reflow back. This is commonly how I mess up, I then git difftool with something like winmerge and revert the comments one by one. Comment Actions With your patch I still see the bug in this case: struct S { /*comment*/ S(const S &) = default; void f() = default; S &operator =(S); }; Mind the operator =. Another failure: struct S { /*comment*/ S(const S &) = default; void f() = default; S &operator/**/ =(S) {} }; As mentioned yesterday, comment between operator and =. Note, /*comment*/ is there just to make the spacing more visible. It's unrelated to the bug otherwise.
Comment Actions I was tinkering with the use of getPreviousNonComment last night before signing off and the problem that I noticed was that, though it stops the operator= from being split and aligned with previous lines, it adds a single space: /* long long padding */ int() = default; int &operator() = default; -int &operator/**/=(); +int &operator/**/ =(); Going to mess around with it some more today, but do you have any ideas as to why that might be happening? Comment Actions
As of right now, it doesn't fix 33044. Should I investigate and see if I can get this addressed in the same patch, or should it be considered a separate bug? Comment Actions
A different one please. Comment Actions
I don't think it's related to getPreviousNonComment, but to the fact that we add spaces after block comments.
It will be certainly a different patch, I had just thought that your patch would fix it tangentially. glotchimo marked 4 inline comments as done. Comment ActionsUse getPreviousNonComment to account for inline comments.
glotchimo marked an inline comment as done. Comment ActionsSimplify by removing look-ahead (unnecessary b/c of difference between ident and operator tokens). Comment Actions LGTM. Let's wait a day or two before landing to let other reviewers chime in. Do you need help landing? This revision is now accepted and ready to land.Jan 17 2022, 11:44 PM Comment Actions Amazing, thank you. This is my first patch so I will need help landing, but I will also apply for commit access as I intend to keep contributing. Here is my name and email for this commit: Elliott Maguire <glotchimo@pm.me> This revision was landed with ongoing or failed builds.Jan 19 2022, 1:19 AM Closed by commit rG480a1fab72f4: [clang-format] Fix incorrect alignment of operator= overloads. (authored by glotchimo, committed by curdeius). · Explain Why This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 400354 clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp
|
Maybe getPreviousNonComment? Cf. test comment.