How to prevent clang-format from adding a single semicolon to a new line?

clang-format 5.0 currently doesn't recognize that type of loop. Unfortunately as of clang-format version 5, you won't get a setting that does what you need.

Looking up the Clang Format Style Options, the closest that I've found is AllowShortLoopsOnASingleLine: true, but that setting doesn't recognize the loop condition as being the body of the loop.

As long as clang-format doesn't recognize those kinds of loops, what I'd do is to mark it your code with // clang-format off and then // clang-format on around your block of code.


Apparently this is not possible, but a workaround could be to replace the semicolon with an empty block. If both AllowShortLoopsOnASingleLine and AllowShortBlocksOnASingleLine are set, than it will be formatted as

while (fread(pixel_array++, sizeof(byte), 3, fp)) {}