<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/136497>136497</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format]:Feature Request Add option to disable space before braces
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
JM-FRANK
</td>
</tr>
</table>
<pre>
**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!
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEVt1yozgTfRr5pisUyD-YC19gJ66a70smU5PZ3WshNaCNkFhJOGGffkuCeJI4k0lRcRWg_jnn9GmYc7LRiDuy3pP19YINvjV297-7q-P38uv_F5UR447QktDyGh23svfS6OkGScN1UEw3V0djO-aBD9ai9moE1L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