Menu

#536 Braces not added in for loop when the enclosed statement is if-statement

closed-fixed
nobody
None
2024-01-21
2020-02-17
No

Consider following piece of code:

int main () {
  int i = 0;
  int a, b;

  for (i = 0; i < 5; i++)
    a = i;
  for (i = 0; i < 5; i++)
    if (a == i)
      b = i;
}

I ran astye as follows:

% astyle --version
Artistic Style Version 3.1
% astyle --style=allman --break-blocks --pad-oper --pad-paren-out --pad-header --unpad-paren --align-pointer=middle --add-brackets --convert-tabs --break-return-type --options=none test.c

int main ()
{
    int i = 0;
    int a, b;

    for (i = 0; i < 5; i++)
    {
        a = i;
    }

    for (i = 0; i < 5; i++)
        if (a == i)
        {
            b = i;
        }
}

The braces are added to first for loop but not to the second one.
Please fix it.

Regards,
Sulabh

Discussion

  • André Simon

    André Simon - 2024-01-12
    • status: open --> open-fixed
     
  • André Simon

    André Simon - 2024-01-12

    Please try --add-braces=nested in the new release 3.4.11.

     
  • André Simon

    André Simon - 2024-01-21
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB