Fixes https://github.com/llvm/llvm-project/issues/31568.
Added a check for operator keyword tokens.
Differential D117421
[clang-format] Fix incorrect alignment of operator= overloads. glotchimo on Jan 16 2022, 12:36 AM. Authored by
Details
Diff Detail
Unit Tests 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? 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 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.
Comment Actions Simplify 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? 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> |
Maybe getPreviousNonComment? Cf. test comment.