4 ms·
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 i
by iainmerrick 11y ago
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.
- gravypod 11y agoWouldn'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.
- iainmerrick 11y agoThat's a good policy for code reviews, but again it's hard to do it correctly in a tool. 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.
- mikaraento 11y agoI've found improving style checks file-by-file to be a reasonable approach: - all new files are checked - old files are put in a whitelist for the style checker, the submitter is supposed to remove the file from the whitelist when signifcant changes are made
- gravypod 11y agoI'm very glad to see that I'm not the only one who does this. I wanted to see if others felt that this process worked. It is good to hear others are doing it.
- jjuhl 11y agoEver heard of clang-format? http://clang.llvm.org/docs/ClangFormat.html http://clang.llvm.org/docs/ClangFormat.html
- unwind 11y agoOf course, that's the (silent) assumption. But humans sometimes fail to do this, which is why the warning is helpful. Very nice to see this in GCC.
- seiji 11y agoAutomatic brace insertion program with helper scripts: https://matt.sh/howto-c#_formatting https://matt.sh/howto-c#_formatting It is never an error to insert braces, and the rules for inserting braces are fully deterministic in C.