0

I'm trying to achieve the following clang formatings for if and else blocks:

1.For empty blocks, i'd like to keep them (single lined) on the same line as the end of the condition or right after the else, like

1.1

if (true) {}
else {}

1.2

if (true
    ) {}
else {}

1.3

  if (true


            ) {}


    else {}

2.Non-empty blocks should always be wrapped after the control statement and before and after the else

2.1

if (true)
{
    ;
}
else
{
    ;
}

2.2

if (true) {}
else
{
    ;
}

2.3

if (true)
{
    ;
}
else {}

2.4

if (true)
{
    // is this true
}
else
{
    /* this might be false */
}

3.but never

3.1.1

if (true) {
    ;
}
else {
    ;
}

3.1.2

if (true) {
    ;
} else {
    ;
}

3.1.3

if (true)
{
    ;
} else
{
    ;
}

3.1.4

if (true)
{
    ;
} else
{
    ;
}

3.2.1

if (true) {
}
else {
}

3.2.2

if (true) {
} else {
}

3.2.3

if (true)
{
} else
{
}

3.2.4

if (true)
{
} else
{
}

I'm not able to find a solution for the empty blocks.

jesses
  • 559
  • 3
  • 15
  • 3
    Why are you writing empty blocks? – super Oct 14 '20 at 09:17
  • maybe enumerate your examples. I find it confusing to have so many so similar cases – 463035818_is_not_an_ai Oct 14 '20 at 09:29
  • @super Because of https://stackoverflow.com/questions/35053371/what-is-the-benefit-of-terminating-if-else-if-constructs-with-an-else-clause (I'm aware that it's named misra-C and not misra-cpp but that's what ppl defined for our code base) – jesses Oct 14 '20 at 09:50
  • @idclev463035818 I don't understand what you mean by enumerate. I tried to describe in few words but gave example in case that those are not accurate enough since english is not my first or second language. Can you elaborate? – jesses Oct 14 '20 at 09:52
  • enumerate: "1. with `;`: 1.1 `first example` 1.2 `second example` 2. without `;` 2.1 ...." it was just a suggestion... – 463035818_is_not_an_ai Oct 14 '20 at 09:53
  • @idclev463035818 oh, ic. The question was really honest and it's a good idea. Thanks! – jesses Oct 14 '20 at 11:20

0 Answers0