This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] [PR43531] clang-format damages "alternative representations" for operators
ClosedPublic

Authored by MyDeveloperDay on Oct 2 2019, 6:01 AM.

Details

Summary

https://bugs.llvm.org/show_bug.cgi?id=43531

Fix for clang-format incorrectly handles "alternative operators" as described by https://en.cppreference.com/w/cpp/language/operator_alternative

compl = ~
not = !

these are unary operators, and clang-format will remove the space between them and a numeric constant

this incorrectly formats the following code

int a compl 5;
int a not 5;

into:

int a compl5;
int a not5;

The code adds FIXME unit tests for "alternative token" representations for {} [] and # as defined by the same link, which would require a more detailed change to the FormatTokenLexer

Diff Detail

Event Timeline

MyDeveloperDay created this revision.Oct 2 2019, 6:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 2 2019, 6:01 AM
mitchell-stellar requested changes to this revision.Oct 3 2019, 12:35 PM
mitchell-stellar added inline comments.
clang/lib/Format/TokenAnnotator.cpp
2904

Without context, "compl5" and "not5" do not make sense. Can you try to rephrase this comment?

2908

For consistency, Left.TokenText == "not" may be better. I cannot find another instance of .equals().

clang/unittests/Format/FormatTest.cpp
14613

Instead of using a URL link, perhaps describe in words what this test is supposed to do?

This revision now requires changes to proceed.Oct 3 2019, 12:35 PM
MyDeveloperDay marked 3 inline comments as done.
  • add additional compl(5) and not(5) unit tests
  • improve the comments around the condition and explaining the tests
  • remove the use of .equals(...)
This revision is now accepted and ready to land.Oct 4 2019, 7:10 AM
This revision was automatically updated to reflect the committed changes.