clang-format: Allow empty records on a single line
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Feel free to close this if this is already possible and I just failed to figure out how.
There doesn't appear to be a way to accomplish this with clang-format:
```cpp
// Break before braces after class/struct/union:
struct Foo
{
int x;
};
// AND allow empty class/struct/union on a single line:
struct Foo {};
```
If we set `BraceWrapping: AfterStruct: true` and `BraceWrapping: SplitEmptyRecord: false`, we instead get this:
```cpp
struct Foo
{};
```
My proposal would be to add a `bool AllowEmptyRecordsOnASingleLine` option that handles this case similarly to the `AllowShortEnumsOnASingleLine` option. If others think this would be an acceptable enhancement, I can look into implementing it myself, but I thought I'd request feedback before I put in the work.
Contributor guide
Research direction
Start by locating clang-format's handling of BraceWrapping, SplitEmptyRecord, and AllowShortEnumsOnASingleLine. Check the existing formatting tests for records and empty constructs; done means non-empty records still break before braces while empty records format as `struct Foo {};`.
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