简体   繁体   中英

Newline between bodieless while loops and semicolon

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM