Clang-format syntax to get initializer opening brace on its own line

Viewed 243

I'm writing C-code using Visual Studio Code with a .clang-format file. I've got all of the formatting the way I want it, with the exception of structure initializations. I would like this format -

static ifc_t _ifc = 
{
    .ps_read = NULL,
};

but instead, I'm getting this -

static ifc_t _ifc = {
    .ps_read = NULL,
};

My clang-format file having to do with opening braces is this -

BreakBeforeBraces: Custom
BraceWrapping:
  AfterClass:      true
  AfterControlStatement: true
  AfterEnum:       true
  AfterExternBlock: true
  AfterFunction:   true
  AfterNamespace:  true
  AfterObjCDeclaration: true
  AfterStruct:     true
  AfterUnion:      true
  BeforeCatch:     true
  BeforeElse:      true
  IndentBraces:    false

Is there another clang-format setting to control the position of the opening brace on a structure initialization? Thanks...

1 Answers

Appears there's an existing PR to address this deficiency by adding the missing BraceWrapping / BeforeStructInitialization (https://reviews.llvm.org/D91949), but it's sadly stalled since 2021-05-27 with "revisions needed".

Related