I'm using BreakBeforeBraces: Allman
in my .clang-format
file, but braces in control statements (such as if
, for
, while
, ...) are not being put on their own line.
// Currently:
void foo()
{
while(true) {
bar();
}
}
// What I want:
void foo()
{
while(true)
{
bar();
}
}
I've read that you can set nested configuration classes for braces in BraceWrapping
, but I could't figure out the correct YAML syntax (and JSON syntax for the sublime text plugin), and couldn't find any existing example.
Is there any way of doing this?
Achieving the desired result with a specific combination of style options is impossible at the moment. I've reported the issue as bug 25069.
It looks like clang-format-3.8 has individual options for breaking when BraceWrapping is set to custom now.
This is still a bug as of clang-format 5.0.1. The key combination is
AllowShortBlocksOnASingleLine: true
and any otherAllowShort...OnASingleLine
option. Having both options set seems to negate the Allman brace style. IfAllowShortBlocksOnASingleLine: false
then you can control to your heart's content.