Description
Description
Clang-Format currently enforces a space before opening braces {
for code blocks (functions, control statements, etc.)
, generating:
void function() { ... }
if (condition) { ... }
Request: Introduce a new configuration option (e.g., SpaceBeforeBrace) to allow disabling this space, achieving:
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:
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:
BasedOnStyle: LLVM
SpaceBeforeBrace: None
BreakBeforeBraces: Attach
Formatted Code:
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!