Skip to content

[clang-format] return type can be split on namespace when member template has comment #153891

@joelhock

Description

@joelhock

clang-format version 20.1.0 (https://github.com/llvm/llvm-project.git 24a30da) formatted code like this:

// ---
// IndentWidth:     4
// PenaltyReturnTypeOnItsOwnLine: 800

class MyClass {
    template <bool abool, // a comment
              bool anotherbool>
    static inline std::pair<size_t, MyCustomTypeeeeeeeee>
    myfunccccccccccccccccccccccc(const char *buf, const char *&err);
};

whereas clang-format version 21.1.0-rc3 (https://github.com/llvm/llvm-project.git 6096d35) splits the std:: from the rest of the return type:

// ---
// IndentWidth:     4
// PenaltyReturnTypeOnItsOwnLine: 800

class MyClass {
    template <bool abool, // a comment
              bool anotherbool>
    static inline std::
        pair<size_t, MyCustomTypeeeeeeeee> myfunccccccccccccccccccccccc(
            const char *buf, const char *&err);
};

i could see this being "as designed," but what's odd is that if the comment in the member template is removed, the formatting 21.1.0-rc3 does changes back to how clang version 20.1.0 did it:

// ---
// IndentWidth:     4
// PenaltyReturnTypeOnItsOwnLine: 800

class MyClass {
    template <bool abool, bool anotherbool>
    static inline std::pair<size_t, MyCustomTypeeeeeeeee>
    myfunccccccccccccccccccccccc(const char *buf, const char *&err);
};

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions