0

While using uncrustify, I encountered a problem with while loops. If the while loop has no body, a trailing semicolon will get pushed to the next line. On the GitHub and on this website I found no mention of this whatsoever. Is the problem related to forcing one liners in different lines?

The code I tried it with is: (This is also what it should look like in the end)

int main()
{
    int i = 20000;
    while(i--);
    return 0;
}

But what uncrustify returns is:

int main()
{
    int i = 20000;
    while (i--)
        ;
    return 0;
}

Config file: https://pastebin.com/3FUqHmp8

double-beep
  • 5,031
  • 17
  • 33
  • 41
InfoMathze
  • 176
  • 6

1 Answers1

0

With an empty config file this does not happen so this behavior is caused by a option that you added in the config file that you are using (most likely one of the nl_* options).

Post a link to your file.


Both of this options are causing this behavior:

# Add or remove newline between 'while' and '{'.
nl_while_brace                  = force    # ignore/add/remove/force

# Change a one-liner while statement into simple unbraced while
# 'while (i<5) foo(i++);' => 'while (i<5)\n foo(i++);'.
nl_split_while_one_liner        = true     # false/true

Keep in mind that Uncrustify also considers missing braces (virtual braces) to be braces (nl_while_brace).

Uncrustify has an option to disable handling of vbraces for spacing options but it seems that it is missing it for newline options. If you need that open up a feature or pull request on the github repository site: https://github.com/uncrustify/uncrustify.

CDanU
  • 156
  • 1
  • 9
  • Ok, I tough about this vbrace stuff, but thought it might only apply to spaces, not newlines. I guess, I have to open a feature request for that. I unfortunately can't upvote your answer as of yet (not enough reputation). Thank you for your effort! – InfoMathze Sep 06 '17 at 14:14