This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Disallow trailing return arrows to be operators
ClosedPublic

Authored by rymiel on Sep 16 2022, 7:52 AM.

Details

Summary

In the following construction:
template <typename T> requires Foo<T> || Bar<T> auto func() -> int;

The -> of the trailing return type was actually considered as an
operator as part of the binary operation in the requires clause, with
the precedence level of PrecedenceArrowAndPeriod, leading to fake
parens being inserted in strange locations, that would never be closed.

Fixes one part of https://github.com/llvm/llvm-project/issues/56213
(the rest will probably be in a separate patch)

Diff Detail

Event Timeline

rymiel created this revision.Sep 16 2022, 7:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 16 2022, 7:52 AM
rymiel requested review of this revision.Sep 16 2022, 7:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 16 2022, 7:52 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rymiel added a project: Restricted Project.Sep 16 2022, 7:52 AM
MyDeveloperDay added inline comments.Sep 16 2022, 9:43 AM
clang/unittests/Format/TokenAnnotatorTest.cpp
448

should you not check that Tokens[21] is a TT_TrailingReturnArrow?

rymiel added inline comments.Sep 16 2022, 9:54 AM
clang/unittests/Format/TokenAnnotatorTest.cpp
448

That's probably a good idea, thank you! (though the bug wasn't that -> was misannotated, it was still a trailing return arrow, it just caused fake parentheses to be inserted earlier on)

rymiel updated this revision to Diff 460810.Sep 16 2022, 9:57 AM

Also test the annotated value of the arrow

rymiel marked an inline comment as done.Sep 16 2022, 9:57 AM
HazardyKnusperkeks added inline comments.
clang/lib/Format/TokenAnnotator.cpp
2615
clang/unittests/Format/TokenAnnotatorTest.cpp
448

Can you add the test for ClosesRequiresClause?

This revision is now accepted and ready to land.Sep 16 2022, 1:28 PM
rymiel updated this revision to Diff 460947.Sep 16 2022, 5:01 PM

Address review comments

rymiel marked 2 inline comments as done.Sep 16 2022, 5:03 PM
owenpan accepted this revision.Sep 16 2022, 10:28 PM

I must humbly say that I do not think I qualify under "a track record of submitting high quality patches", I've only done incidental bug fixes that are in easily approachable places. Do you disagree with my self-assessment? (I also understand that I've made lots of extremely tiny patches that are probably a little annoying to manage)

I must humbly say that I do not think I qualify under "a track record of submitting high quality patches", I've only done incidental bug fixes that are in easily approachable places. Do you disagree with my self-assessment? (I also understand that I've made lots of extremely tiny patches that are probably a little annoying to manage)

Yes you do, I had far less when I got my commit access.

I must humbly say that I do not think I qualify under "a track record of submitting high quality patches", I've only done incidental bug fixes that are in easily approachable places. Do you disagree with my self-assessment?

I think you should have commit access based on the patches you have submitted and wouldn't have asked otherwise.

(I also understand that I've made lots of extremely tiny patches that are probably a little annoying to manage)

Tiny patches, when appropriate, are actually more manageable. :)

Thank you for the vote of confidence!! It went way more quickly than I expected; I now already have commit access!

@rymiel you definitely deserve the commit access: comments and initial investigations and possible bug locations in github issues, defect focused initial commits, way to go!, Welcome aboard..