Live data from Hacker News

GCC 6: -Wmisleading-indentation vs. “goto fail;”

developerblog.redhat.com

1–10 of 168 posts

Re: GCC 6: -Wmisleading-indentation vs. “goto fail;”

#4
post #2

This 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.

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.

Re: GCC 6: -Wmisleading-indentation vs. “goto fail;”

#6
post #2

This 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;”

#7
post #2

This 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.

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;”

#9
post #2

This 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.

I always opt out of the "no braces needed thing," it is my feeling that you should stick to the more "all around" method of writing something so you never need to switch back and forth..

Re: GCC 6: -Wmisleading-indentation vs. “goto fail;”

#10
post #2

This 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.

Even if you ignore safety, braces are still better because if need to edit the code later, you won't need to change as many lines, so the source control history will be cleaner. (Similar to adding a trailing "," to lists that don't strictly need it.)
Post reply on HN