This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Put peekNextToken(/*SkipComment=*/true) to good use
ClosedPublic

Authored by owenpan on Jan 23 2023, 3:43 PM.

Details

Summary

To prevent potential bugs in situations where we want to peek the next non-comment token.

Diff Detail

Event Timeline

owenpan created this revision.Jan 23 2023, 3:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 3:43 PM
owenpan requested review of this revision.Jan 23 2023, 3:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 3:43 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
owenpan added inline comments.Jan 23 2023, 3:55 PM
clang/lib/Format/UnwrappedLineParser.cpp
3592–3601

We should pass true to peekNextToken() on Line 3597 here, but removing this entire case would have no effect on the existing unit test (Line 23693 in FormatTest.cpp). @HazardyKnusperkeks any idea?

rymiel added inline comments.Jan 23 2023, 6:08 PM
clang/lib/Format/UnwrappedLineParser.cpp
3592–3601

The peeking is there because of https://reviews.llvm.org/D134325, it has no format tests, only an annotator test

rymiel added inline comments.Jan 23 2023, 6:12 PM
clang/lib/Format/UnwrappedLineParser.cpp
3592–3601

Also, I don't think that function is involved in concept declarations since https://reviews.llvm.org/D140339

owenpan added inline comments.Jan 23 2023, 6:44 PM
clang/lib/Format/UnwrappedLineParser.cpp
3592–3601

So which tests were meant to check the kw_bool case here?

rymiel added inline comments.Jan 23 2023, 8:46 PM
clang/lib/Format/UnwrappedLineParser.cpp
3592–3601

Well, originally the one you mentioned on line 23693, but since the code paths have been changed, I think it's really only the one added in https://reviews.llvm.org/D134325

MyDeveloperDay accepted this revision.Jan 24 2023, 12:28 AM
MyDeveloperDay added inline comments.
clang/lib/Format/UnwrappedLineParser.cpp
3592–3601

I love the new annotator tests, but we should probably always try to add a verifyFormat test as well even if its trivial in the future, just so we have some context as to what type of code warranted the change.

This revision is now accepted and ready to land.Jan 24 2023, 12:28 AM
HazardyKnusperkeks added inline comments.
clang/lib/Format/UnwrappedLineParser.cpp
3592–3601

As far as I can see it does not only can be removed, it should be removed.

bool can not appear on the top level of a requires clause. As @rymiel said it is there for the concepts, which are now handled differently.

owenpan added inline comments.Jan 24 2023, 6:32 PM
clang/lib/Format/UnwrappedLineParser.cpp
3592–3601

@rymiel @HazardyKnusperkeks thanks for the explanations. Can we remove the kw_bool case then?

This revision was landed with ongoing or failed builds.Jan 24 2023, 6:40 PM
This revision was automatically updated to reflect the committed changes.
owenpan added inline comments.Jan 24 2023, 6:45 PM
clang/lib/Format/UnwrappedLineParser.cpp
3592–3601

As far as I can see it does not only can be removed, it should be removed.

Okay, I will leave it to you or @rymiel then. :)

rymiel added inline comments.Jan 24 2023, 7:07 PM
clang/lib/Format/UnwrappedLineParser.cpp
3592–3601

As far as I can see it does not only can be removed, it should be removed.

You are right! I forgot the fact that this only ever applied for concepts, and the bug fix only ever worked around that. I had it backwards in my head because the bug affected requires clauses too.