[clang-format] Incorrect formatting with multiple `requires` clauses
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The following C++ code does not format correctly using clang-format version 23.1.0 and the LLVM style:
```c++
template
concept NotRange = !std::ranges::range>;
template
requires(N > 2) && (C > 0)
class FormattingTest {
public:
template
requires(sizeof...(Args) > 0)
void f(const Args &...args);
};
template
requires(N > 2) && (C > 0)
template
requires(sizeof...(Args) > 0)
inline void FormattingTest::f(const Args &...args) {}
```
The second template/requires portion of the out-of-class function definition is formatted incorrectly. It seems to be the second `requires` clause driving the issue; commenting it out results in correct formatting:
```c++
template
concept NotRange = !std::ranges::range>;
template
requires(N > 2) && (C > 0)
class FormattingTest {
public:
template
// requires(sizeof...(Args) > 0)
void f(const Args &...args);
};
template
requires(N > 2) && (C > 0)
template
// requires(sizeof...(Args) > 0)
inline void FormattingTest::f(const Args &...args) {}
```
Contributor guide
Research direction
Start by reproducing the issue with clang-format version 23.1.0 using the LLVM style and the C++ example in the report. Compare the out-of-class definition with the expected formatting, then add regression coverage for multiple requires clauses and verify that the corrected output matches the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100