This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Look ahead before consuming `bool` in requires clause.
ClosedPublic

Authored by rymiel on Sep 20 2022, 4:33 PM.

Details

Summary

The comment handling the bool case says:
"bool is only allowed if it is directly followed by a paren for a cast"

This change more closely follows this directive by looking ahead for
the paren before consuming the bool keyword itself. Without a following
paren, the bool would be part of something else, such as a return type
for a function declaration

Fixes https://github.com/llvm/llvm-project/issues/57538

Diff Detail

Event Timeline

rymiel created this revision.Sep 20 2022, 4:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 20 2022, 4:33 PM
rymiel requested review of this revision.Sep 20 2022, 4:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 20 2022, 4:33 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rymiel added a project: Restricted Project.Sep 20 2022, 4:33 PM
zzyyyl added a subscriber: zzyyyl.EditedSep 20 2022, 9:52 PM

What if concept c = (bool)(...) ?

or concept c = static_cast<bool>(...)

What if concept c = (bool)(...) ?

or concept c = static_cast<bool>(...)

Aren't these handled elsewhere in the case (by the static_cast and l_paren rules)? but possibly worth a test either an annotation test or an actual formatting example.

given that #57538 manifested itself as a incorrect format (no doubt because of incorrect token annotation), should we add a verifyFormat tests somewhere for the example from the github issue, (it just protects the formatting for being broken by some other change)

Thanks for the fix.

given that #57538 manifested itself as a incorrect format (no doubt because of incorrect token annotation), should we add a verifyFormat tests somewhere for the example from the github issue, (it just protects the formatting for being broken by some other change)

Yeah we disagree here, but I have to redisagree.
It's the wrong annotation, it's not related to any formatting. And the format tests cpp is a monster.

This revision is now accepted and ready to land.Sep 21 2022, 4:19 AM
owenpan added inline comments.Sep 21 2022, 12:03 PM
clang/lib/Format/UnwrappedLineParser.cpp
3534

Redundant as it's asserted at the start of parseParens() below?

rymiel updated this revision to Diff 462670.Sep 24 2022, 7:08 AM

Remove redundant assert

thank you for pointing that out

rymiel marked an inline comment as done.Sep 24 2022, 7:08 AM
owenpan accepted this revision.Sep 24 2022, 7:49 AM
MyDeveloperDay accepted this revision.Sep 24 2022, 9:15 AM