Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brevzin opened this issue May 30, 2025 · 2 comments · Fixed by #142251
Closed

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

brevzin opened this issue May 30, 2025 · 2 comments · Fixed by #142251
Assignees
Labels
clang-format regression:18 Regression in 18 release

Comments

@brevzin
Copy link
Contributor

brevzin commented May 30, 2025

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.

@brevzin brevzin changed the title clang-format regression with spaces around trailing-return-type clang-format regression with spaces around trailing-return-type in macro May 30, 2025
@llvmbot
Copy link
Member

llvmbot commented May 30, 2025

@llvm/issue-subscribers-clang-format

Author: Barry Revzin (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:
```cpp
#define DEFINE_CHECKED(name, op)                                                                   \
    template &lt;typename R, std::integral A, std::integral B&gt;                                        \
    constexpr auto checked_##name(A a, B b) -&gt; CheckedResult&lt;R&gt; {                                  \
        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 &lt;typename R, std::integral A, std::integral B&gt;                                        \
    constexpr auto checked_##name(A a, B b)-&gt;CheckedResult&lt;R&gt; {                                    \
        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.

@brevzin
Copy link
Contributor Author

brevzin commented May 31, 2025

Thanks @owenca!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format regression:18 Regression in 18 release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants