This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Allow line break between template closer and right paren
AbandonedPublic

Authored by rymiel on Dec 17 2022, 5:56 PM.

Details

Summary

This allows for AlignAfterOpenBracket: BlockIndent to work correctly
when using values with type parameters.

Line breaks after any template closer was disallowed 10 years ago, in
90e51fdbab33d43e0d4f932c2d90d0b86e865664, as a fix to https://github.com/llvm/llvm-project/issues/15158.
Allowing it again, but only if preceding a specific character, seems to
work out fine.

Note that this change originally caused a test failure in FormatTestJS.NoBreakAfterAsserts,
which is why there is an explicit negative check against TT_JsTypeColon.

Given this, I'm not 100% confident in this change not producing defects,
especially in other languages, but that was the only one in the test
suite.
Perhaps additional restrictions should be used, such as requiring
BAS_BlockIndent to be set.

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

Diff Detail

Event Timeline

rymiel created this revision.Dec 17 2022, 5:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 17 2022, 5:56 PM
rymiel requested review of this revision.Dec 17 2022, 5:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 17 2022, 5:56 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rymiel added a project: Restricted Project.Dec 17 2022, 6:48 PM

Maybe do not limit to JsTypeColon but all colons? What about something like f(some_template<Variable>).method()? I'd have to check where it breaks if there isn't a template in the argument, but I'd guess not before the paren.

clang/lib/Format/TokenAnnotator.cpp
4953–4958

Could you merge this?

rymiel abandoned this revision.Sep 1 2023, 3:12 PM