Skip to content

[clang-format] Ability to configure breaking after short return types #78010

Closed
@rmarker

Description

@rmarker

Currently, when AlwaysBreakAfterReturnType is None, line breaks are prevented after 'short' return types.

From ContinuationIndenter.cpp

// Don't break after very short return types (e.g. "void") as that is often
// unexpected.
if (Current.is(TT_FunctionDeclarationName) && State.Column < 6) {
  if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None)
    return false;
}

Note, that 'short' here isn't the length of the type itself, but the column where the type finishes.
So, the indentation can change the behaviour.

While the comment says that breaking would be unexpected, this behaviour takes precedence over any of the penalty options for configuring where to place line breaks. It is fairly specific behaviour and can also be unexpected as it avoids breaking after the return type seemly ignoring the penalty configuration.

It would be helpful if there was a way that this could be configured.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions