This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Treats &/&& as reference when followed by ',' or ')'.
ClosedPublic

Authored by red1bluelost on Nov 9 2022, 5:45 PM.

Details

Summary

Ran into an issue where function declarations inside function scopes or uses
of sizeof inside a function would treat the && in 'sizeof(Type &&)' as a binary
operator.

Attempt to fix this by assuming reference when followed by ',' or ')'. Also adds
tests for these.

Also hit an edge case in another test that treated "and" the same as "&&"
since it parses as C++. Changed the "and" to "also" so it is no longer a
keyword.

GitHub issue at: https://github.com/llvm/llvm-project/issues/58923

Diff Detail

Event Timeline

red1bluelost created this revision.Nov 9 2022, 5:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2022, 5:46 PM
red1bluelost requested review of this revision.Nov 9 2022, 5:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2022, 5:46 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
red1bluelost edited the summary of this revision. (Show Details)Nov 9 2022, 5:48 PM
MyDeveloperDay added a project: Restricted Project.

Its always good if you have a github issue to add that to the summary (just to tie stuff together), if you don't feel free to go over there an log a bug.

clang/lib/Format/TokenAnnotator.cpp
2360

nowadays we add a TokenAnnotator test (they are very easy to write), this lets us ensure its getting annotated correctly. (which is really the bug here),

but your tests below are great too!.

On first inspection this looks ok, but lets wait for the others chime in, please add the annotator test too.

MyDeveloperDay requested changes to this revision.Nov 10 2022, 2:46 AM
This revision now requires changes to proceed.Nov 10 2022, 2:46 AM

Adds tests for the TokenAnnotator as well.

red1bluelost edited the summary of this revision. (Show Details)Nov 10 2022, 2:38 PM
red1bluelost marked an inline comment as done.

Made a GitHub issue and addressed the current comments. :)

clang/lib/Format/TokenAnnotator.cpp
2360

Thanks for the suggestion! Didn't realize there were tests for the tokenizer. I got those added now.

MyDeveloperDay accepted this revision.Nov 10 2022, 3:07 PM

For me this looks good, but please wait for one of the others to double confirm.

This revision is now accepted and ready to land.Nov 10 2022, 3:07 PM
owenpan accepted this revision.Nov 11 2022, 1:00 AM
red1bluelost marked an inline comment as done.Nov 11 2022, 12:01 PM

I noticed that the Premerge seemed ran into an issue with 'InsertBraces'. It looks to me that it is unrelated and probably due to the pre-merge machine using a pre-15 clang-format (I ran into similar issue on my local machine).

If it is unrelated, could a reviewer commit on my behalf? Name and email is "Micah Weston" and micahsweston@gmail.com

Thanks for the helpful reviews!

This revision was landed with ongoing or failed builds.Nov 12 2022, 1:00 AM
This revision was automatically updated to reflect the committed changes.