Skip to content

clang-format regression with spaces around trailing-return-type in macro #142178

@brevzin

Description

@brevzin

Here is my clang-format file:

BasedOnStyle: llvm

AccessModifierOffset: -4
AlignConsecutiveBitFields: Consecutive
AlignEscapedNewlines: Right
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BraceWrapping:
  BeforeElse: true
  BeforeCatch: true
ColumnLimit: 100
ConstructorInitializerAllOnOneLineOrOnePerLine: true
IndentWidth: 4
InsertBraces: true
NamespaceIndentation: None
PenaltyBreakAssignment: 60
PenaltyBreakBeforeFirstCallParameter: 175
PointerAlignment: Left
QualifierAlignment: Custom
QualifierOrder: ['static', 'inline', 'constexpr', 'type', 'const', 'volatile']
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: true
SpacesBeforeTrailingComments: 2
SpacesInSquareBrackets: false

On clang 17.0.6, I get this formatting:

#define DEFINE_CHECKED(name, op)                                                                   \
    template <typename R, std::integral A, std::integral B>                                        \
    constexpr auto checked_##name(A a, B b) -> CheckedResult<R> {                                  \
        return something_interesting(a, b);                                                        \
    }

DEFINE_CHECKED(add, +)

On clang 18.1.4 and later, I started getting this formatting:

#define DEFINE_CHECKED(name, op)                                                                   \
    template <typename R, std::integral A, std::integral B>                                        \
    constexpr auto checked_##name(A a, B b)->CheckedResult<R> {                                    \
        return something_interesting(a, b);                                                        \
    }

DEFINE_CHECKED(add, +)

The spaces around the trailing-return-type are now absent, as if the formatter things this is class member access instead of being a function declaration. I'm not sure exactly when the change happened, those are just two versions I have handy.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions