llvm / llvm/llvm-project

[clang-format] Option to place names of functions, constructors and destructors on a new line

Open
#161,730 1 comment 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

I would like to place names of functions, constructors and destructors (declarations and inline definitions) on a new line and leave all possible specifiers (such as `explicit`, `constexpr`, attributes and so on) on a separate line before the function name.

Currently it is possible only for function names using `BreakAfterReturnType: All`, but constructors and destructors have no return type.

Input:
```c++
class SomeClass {
public:
constexpr SomeClass() noexcept = default;

constexpr explicit SomeClass(int x);

[[nodiscard]] std::shared_ptr foo();
};
```

Desired output:
```c++
class SomeClass {
public:
constexpr
SomeClass() noexcept = default;

constexpr explicit
SomeClass(int x);

[[nodiscard]] std::shared_ptr //< Formatted by BreakAfterReturnType: All
foo(); //<
};
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue's C++ input with clang-format and compare it with BreakAfterReturnType: All. Trace the formatting path for function names, then determine how constructors, destructors, declarations, inline definitions, and preceding specifiers should behave. Done means the shown cases produce the desired line breaks without regressing existing function-name formatting.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.