llvm / llvm/llvm-project

[clang-format] BreakAfterReturnType issues

Open
#176,910 3 comments 0 reactions 0 assignees View on GitHub
clang-format
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The BreakAfterReturnType setting for clang-format contains `ExceptShortType`, but this setting is nearly useless or unexpected, since it's the same as `Automatic` just not for short types. But you can easily configure `PenaltyReturnTypeOnItsOwnLine` that it does this with `Automatic`, but there is no way to force line breaks except it's short like a `PenaltyReturnTypeNotOnItsOwnLine` setting.

My proposal is, to either
- remove the constraint, that `ExceptShortType` falls back to `Automatic` if not short (whatever short is ???) and instead gets an additional parameter to tell, which type is still short (e.g. 4 for `auto`). Rest is force split or add another parameter, to switch between the current solution and force split.
- add another `PenaltyReturnTypeNotOnItsOwnLine` setting, adding inverse penalties for exact that usecase.
- allow negative penalties

Last but not least, this setting only applies to usual return types,
There is no way to customize TrailingReturnTypes. So we actually need some sort of `BreakBeforeTrailingReturnTypes`, with similar semantics.

Contributor guide

Open the contributing guide

Research direction

Start by reading the clang-format implementation and documentation for BreakAfterReturnType, especially the ExceptShortType and trailing-return-type behavior described here. Compare the proposed penalty, negative-penalty, and new-setting approaches; the work is done when one precise behavior and its configuration semantics are agreed and covered by the relevant clang-format tests.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.