GCC 6: -Wmisleading-indentation vs. “goto fail;”
11–20 of 168 posts
Re: GCC 6: -Wmisleading-indentation vs. “goto fail;”
#12Earlier quoted context omitted.
This warning is a practical solution to a real problem (of which the famous "goto fail" is an example). Using braces everywhere is definitely good style, but it isn't a practical solution because there's a ton of existing C/C++ code that doesn't use braces.
Wouldn't it make sense to update that as you change the code? If you edit an if statement, you should add the braces in. It would make sure that no new errors are introduced due to this.
The compiler would need to require braces in new code, but allow brace-free style in old code; you'd need to integrate it with the source control system so it knows what code is new. Doable, but tricky.
Re: GCC 6: -Wmisleading-indentation vs. “goto fail;”
#13I'm glad Python (with semantic whitespace) and Go (with gofmt) solve this problem.
Re: GCC 6: -Wmisleading-indentation vs. “goto fail;”
#14Earlier quoted context omitted.
This warning is a practical solution to a real problem (of which the famous "goto fail" is an example). Using braces everywhere is definitely good style, but it isn't a practical solution because there's a ton of existing C/C++ code that doesn't use braces.
Wouldn't it make sense to update that as you change the code? If you edit an if statement, you should add the braces in. It would make sure that no new errors are introduced due to this.
Re: GCC 6: -Wmisleading-indentation vs. “goto fail;”
#15This seems like it could have been avoided by people using braces around every block. Omitting braces in this case leads to a lot of problems.
I'm in favor of braces around everything, but to be honest even I will occasionally use the indent if I only expect one action. e.g. if (true) foo(); else bar(); This looks prettier to my eyes than if(true){ foo(); } else { bar(); } However, I might not be the last person to touch the code. My coworker might come later and add: if (true) foo(); else bar(); baz(); And hence the indent problem.
Re: GCC 6: -Wmisleading-indentation vs. “goto fail;”
#16This seems like it could have been avoided by people using braces around every block. Omitting braces in this case leads to a lot of problems.
I'm in favor of braces around everything, but to be honest even I will occasionally use the indent if I only expect one action. e.g. if (true) foo(); else bar(); This looks prettier to my eyes than if(true){ foo(); } else { bar(); } However, I might not be the last person to touch the code. My coworker might come later and add: if (true) foo(); else bar(); baz(); And hence the indent problem.
Re: GCC 6: -Wmisleading-indentation vs. “goto fail;”
#17One more case to support -Werror.
Re: GCC 6: -Wmisleading-indentation vs. “goto fail;”
#18What a great idea. It's hard to believe no-one ever did this before! (Or did they?)
Re: GCC 6: -Wmisleading-indentation vs. “goto fail;”
#19Making braces optional in single-statement if/else/while/for clauses is one of the biggest anti-features in C. It's frustrating that it was ported forward to more modern languages like Java, JavaScript, C#, etc. I'm glad Python (with semantic whitespace) and Go (with gofmt) solve this problem.
Re: GCC 6: -Wmisleading-indentation vs. “goto fail;”
#20Making braces optional in single-statement if/else/while/for clauses is one of the biggest anti-features in C. It's frustrating that it was ported forward to more modern languages like Java, JavaScript, C#, etc. I'm glad Python (with semantic whitespace) and Go (with gofmt) solve this problem.
if (ptr) call_oldschool_thingy(ptr);