This is an archive of the discontinued LLVM Phabricator instance.

clang-format: Fix pointer alignment for overloaded operators (PR45107)
ClosedPublic

Authored by hans on Mar 26 2020, 7:31 AM.

Details

Summary

This fixes a regression from D69573 which broke the following example:

$ echo 'operator C<T>*();' | bin/clang-format --style=Chromium
operator C<T> *();

(There should be no space between before the asterisk.)

It seems the problem is in TokenAnnotator::spaceRequiredBetween(), which only looked at the token to the left of the * to see if it was a type or not. That code only handled simple types or identifiers, not templates or qualified types. This patch addresses that.

Please take a look. I'm not familiar with the code here, so comments are welcome.

Diff Detail

Event Timeline

hans created this revision.Mar 26 2020, 7:31 AM
This revision is now accepted and ready to land.Mar 26 2020, 7:32 AM
krasimir accepted this revision.Mar 26 2020, 8:32 AM
krasimir added a subscriber: krasimir.

I think this is an improvement. Accepting with a nit. Thank you!

clang/lib/Format/TokenAnnotator.cpp
2806

Consider using Previous->getPreviousNonComment() here and below to jump over comments.

@MyDeveloperDay : sorry, I must have not refreshed this page and didn't realize you already gave an LGTM until I posted the comment.

hans marked an inline comment as done.Mar 27 2020, 2:48 AM
hans added inline comments.
clang/lib/Format/TokenAnnotator.cpp
2806

Thanks! Doing this, and adding a test that requires it.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 27 2020, 3:11 AM