Re:Useful GCC warning options not enabled by -Wall -Wextra
by clhodapp on Wednesday October 04, 2017 @01:25PM
(#15402174)
Perhaps what we really want is a flag to cause the compiler to error for code that would produce undefined behavior and give warnings for the rest? Turning all warnings into errors is a great "worse is better" technique but it seems a bit too coarse-grained to me.
[ Parent
| on HN ]
Re:Useful GCC warning options not enabled by -Wall -Wextra
by eru on Wednesday October 04, 2017 @01:52PM
(#15402525)
Alas, undefined behaviour in C++ and C is in general not that easily detected..
Re:Useful GCC warning options not enabled by -Wall -Wextra
by clhodapp on Wednesday October 04, 2017 @04:04PM
(#15404063)
Oh, to be sure! However, my claim is that if compiler authors are able to add more no-false-positives undefined behavior warnings over time, I kinda want those to "break" the build for my existing software... But if something is just a style check or creates false results, I'd rather the build be allowed to happen.
Re:Useful GCC warning options not enabled by -Wall -Wextra
by withzombies on Wednesday October 04, 2017 @02:27PM
(#15402976)
It's true, but there's a few tools out there to help now, such as tis-interpreter (https://github.com/TrustInSoft/tis-interpreter)
Re:Useful GCC warning options not enabled by -Wall -Wextra
by eru on Thursday October 05, 2017 @12:03PM
(#15410243)
Yes, an interpreter has a much better shot at detecting runtime undefined behaviour than a compiler.
The whole point of undefined behaviour in C and C++ is to let the compiler cheat: ie a Java or Haskell compiler would have to take into account that (i < i + 1) can sometimes be wrong for native ints, and would have to prove that overflow can't happen in order to optimize this comparison away to True. Undefined behaviour in the standard frees C and C++ compilers from these obligations, and they can just assume overflow for signed ints won't happen.
These shortcuts (plus a lot of smarts) make it feasible to write a fast optimizing compiler with the 1970s state of the art in static analysis.
Re:Useful GCC warning options not enabled by -Wall -Wextra
by mjevans on Wednesday October 04, 2017 @08:55PM
(#15406066)
Agreed. If the compiler wants to optimize something because of Undefined Behavior, that's something that -Wall should break on.
'Warning, you have undefined behavior', let the programmer decide what the intent of the section is and fix it.
Re:Useful GCC warning options not enabled by -Wall -Wextra
by Sean1708 on Thursday October 05, 2017 @05:39AM
(#15407820)
Just FYI, not all undefined behaviour can be detected at compile time using current C semantics. I'm very very in favour of cracking down on undefined behaviour and changing things from undefined to implementation-defined and stuff like that, but it's not as easy as just flicking a switch and making the compiler warn whenever it assumes undefined behaviour won't happen.