1

I'm using version of 0.66.1 of uncrustify, and am puzzled by the behavior of 'mod_full_brace_if' which I've set to 'force'. Its comment says:

Add or remove braces on single-line 'if' statement. Will not remove the braces if they contain an 'else'.

Given the line:

if (flag) val = 10;

I hoped/expected it to be transformed to

if (flag) { val = 10; }

Instead it remains unchanged.

Is this just my misunderstanding of the behavior of 'mod_full_brace_if'?

Later: I had some time to do a little experimentation at home. I started off by creating a new format file, and modified some of the settings having to do with forcing braces to be on the same line as various keywords, as well as some settings forcing braces to surround a one-line body. I made a test file with the following contents:

void foo() {
bool flag;
int var;
if (flag) var = 10;
if (!flag)
    var = 20; 
}

Running uncrustify with my new config file yielded the same lack of transformation that I saw at work.

I then created another config file and only changed 'mod_full_brace_if' (to 'force'). Using it on my test file resulted in braces surrounding the bodies of the if statements. Clearly there's some weird interaction of multiple settings. I see some change-a-setting-and-test drudgery in my future.

user888379
  • 1,343
  • 12
  • 30
  • Your example works for me on Uncrustify-0.66.1-2-f9c285db. So it's either something else in your config and/or code. Post links to both. – CDanU Nov 23 '17 at 14:22
  • @CDanU Thanks for the information; it's valuable to know that there's something locally wrong. Unfortunately, the config and sample code are on my work machine, and unavailable to me for the next few days. I can say that my test code was very simple, essentially: – user888379 Nov 23 '17 at 14:57
  • Sorry - got caught by the 5 minute editing limit. The test code was basically a file containing: void foo() { int val; bool flag; if (flag) val = 10; } – user888379 Nov 23 '17 at 15:06

1 Answers1

2

It turns out that the problem was setting "mod_full_brace_if_chain" to "true".

The documentation says:

Make all if/elseif/else statements in a chain be braced or not. Overrides mod_full_brace_if.

If any must be braced, they are all braced. If all can be unbraced, then the braces are removed.

I didn't read the last sentence closely enough when setting the value.

cdhowie
  • 158,093
  • 24
  • 286
  • 300
user888379
  • 1,343
  • 12
  • 30