Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Break after control statements in clang-format

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?

like image 582
Vittorio Romeo Avatar asked Oct 02 '15 12:10

Vittorio Romeo


People also ask

Can clang-format break code?

Short answer: YES. The clang-format tool has a -sort-includes option. Changing the order of #include directives can definitely change the behavior of existing code, and may break existing code.

How do you customize your clang-format?

clang-format supports two ways to provide custom style options: directly specify style configuration in the -style= command line option or use -style=file and put style configuration in the . clang-format or _clang-format file in the project directory.

What is Clangformat?

Clang-Format is a widely-used C++ code formatter. As it provides an option to define code style options in YAML-formatted files — named . clang-format or _clang-format — these files often become a part of your project where you keep all code style rules.


Video Answer


1 Answers

Achieving the desired result with a specific combination of style options is impossible at the moment. I've reported the issue as bug 25069.

like image 196
Vittorio Romeo Avatar answered Sep 28 '22 04:09

Vittorio Romeo