I have a C source file I'm trying to format with clang-format. Ideally, I'd like to have it so that if it sees a one-line block like:
if(condition) { do_something(); }
then, it should leave it alone.
I saw the option AllowShortBlocksOnASingleLine and thought it would do the trick. Instead, what it's done is take the one line block (which I had originally):
if(new_node == NULL) { return; }
and moved the body to the next line like this:
if(new_node == NULL) {
return;
}
along with some other similar blocks. This completely contradicts what I expect should happen.
My .clang-format file is below. What am I doing wrong here?
static Node *
create_node(MAT_VERTEX v)
{
Node *new_node = malloc(sizeof(Node));
if(new_node == NULL) {
return;
}
while(1) {
return;
}
new_node->data = v;
new_node->next = NULL;
return new_node;
enum FOOD breakfast = cereal;
switch(breakfast) {
case eggs: {
int x = 3;
int y;
for(y = 5; y < x; y--) { }
break;
}
case bacon: {
int x = 4;
if(x != 0) {
int y = -5;
}
break;
}
case ham: {
int decision = 1;
int traffic = 1;
if(decision) {
traffic = 0;
do_nothing_function();
}
else {
traffic = 3;
another_do_nothing_function();
}
break;
}
default: {
break;
}
}
}
Language: Cpp
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterFunction: true
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
AllowShortBlocksOnASingleLine: Always
# AllowShortIfStatementsOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
IndentCaseBlocks: false
IndentCaseLabels: true
IndentWidth: 4
PointerAlignment: Right
QualifierAlignment: Leave
SeparateDefinitionBlocks: Leave
AlignAfterOpenBracket: Align
BinPackParameters: false
BinPackArguments: false
AlwaysBreakAfterReturnType: TopLevelDefinitions
MaxEmptyLinesToKeep: 5
IncludeBlocks: Preserve
SortIncludes: Never
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 3
SpacesInContainerLiterals: false
SpacesInSquareBrackets: false