Issue |
136497
|
Summary |
[clang-format]:Feature Request Add option to disable space before braces
|
Labels |
clang-format
|
Assignees |
|
Reporter |
JM-FRANK
|
**Description**
Clang-Format currently enforces a space before opening braces `{` for code blocks (functions, control statements, etc.`)`, generating:
```c
void function() { ... }
if (condition) { ... }
```
Request: Introduce a new configuration option (e.g., SpaceBeforeBrace) to allow disabling this space, achieving:
```c
void function(){ ... }
if (condition){ ... }
```
Why This Matters
Code Style Compliance: Many projects (especially in embedded systems or legacy codebases) mandate brace styles without preceding spaces.
Consistency: Users should have full control over whitespace rules to match team/company guidelines.
Existing Limitations: Current options like BreakBeforeBraces control line breaks but not spaces.
Proposed Solution
Add a configuration option such as:
```yaml
SpaceBeforeBrace: None | Always (default)
```
Examples:
```
SpaceBeforeBrace: None → void f(){ ... }
SpaceBeforeBrace: Always (default) → void f() { ... }
```
Existing options cannot achieve this:
BreakBeforeBraces: Controls line breaks, not spaces.
SpaceBeforeCpp11BracedList: Affects initialization lists only.
SpacesInParensOptions: Irrelevant to brace positioning.
Example Configuration & Output
Desired .clang-format:
```yaml
BasedOnStyle: LLVM
SpaceBeforeBrace: None
BreakBeforeBraces: Attach
```
Formatted Code:
```c
void example(){ // No space before {
if (x > 0){ // No space here either
doSomething();
}
}
```
This feature would significantly enhance Clang-Format’s flexibility. Thank you for considering this request!
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs