Re:Useful GCC warning options not enabled by -Wall -Wextra
by warkdarrior on Wednesday October 04, 2017 @06:14PM
(#15405192)
You can enable/disable warnings in gcc on a line-by-line basis using pragmas:
https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#D...
Re:Useful GCC warning options not enabled by -Wall -Wextra
by usernam on Thursday October 05, 2017 @05:48AM
(#15407862)
I mentioned that. However, push/pop statements require a minimum of 3 lines of pragmas to suppress an unused statement. This doesn't work, you'll end up disabling warnings for entire functions.
Re:Useful GCC warning options not enabled by -Wall -Wextra
by chocolatebunny on Wednesday October 04, 2017 @04:03PM
(#15404044)
Most warnings are just warnings. A warning like "implicit cast from pointer to integer" is a red flag (I got bit by this one). I think there are a few others that are always worth taking a look at.
I like your idea of marking warnings. Warnings should be treated like the messages from any static analysis tool. A lot of times they are worth at least looking at but you should be able to mark them as "not a problem" if you think you know better. That way you will always look at new warnings and not end up ignoring all warnings because there are too many that are irrelevant.
Re:Useful GCC warning options not enabled by -Wall -Wextra
by Asooka on Thursday October 05, 2017 @05:25AM
(#15407746)
For -Wunused specifically, the correct idiom is "(void)x;". It's a no-op that marks x as having been used. Yes, in an ideal world you wouldn't have to do that, but sometimes you're overriding a virtual method and genuinely don't need to use one of the parameters.
People generally "fix" warnings by writing equally useless statements like "x = x" (common for -Wunused). I've seen codebases which aim for zero warnings, but with -Wextra/-Weverything it's just silly. Warnings are supposed to be just that: warnings.
I'd rather want a clean way to suppress the warning and mark it as such instead, so that's hidden by default when the programmer takes note of it.
We have push/pop pragmas, but they are even worse readability-wise. I'd rather have a neighboring comment with dedicated syntax instead.