Skip to content

clang-format: Cannot add a line break between a if-condition clause and its left bracket #114666

@littlebutt

Description

@littlebutt

Description

I want to add a new line between a if-condition clause and its left bracket like that:

Before:

if (condition) {
    // do something
}

After:

if (condition)
{
    // do something
}

After reading the document here, I tried to modify my .clang-format like this:

BasedOnStyle: LLVM
IndentWidth: 4
ColumnLimit: 100
BraceWrapping:
    AfterControlStatement: Always
    BeforeElse: true

But it did not work.

I also want to add a line break around the else statement but I did not find the correct way.

clang-format version

clang-format version 18.1.8

OS

Windows 10 22H2

clang version

clang version 18.1.8
Target: x86_64-pc-windows-msvc
Thread model: posix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions