On 05/10/2017 08:35 AM, Paul.Koning@dell.com wrote:
In GCC at least, you can suppress the warning with an extension: "int foo = foo;" which means "don't initialize but don't bug me".
Thanks, I didn't know about this extension. However, it has undefined behavior in standard C, so we can't use it in code intended to be portable everywhere. And it'd be error-prone even to use it in conditionally-compiled code. Suppose we added this macro: #ifdef __GNUC__ # define INITIALIZED(x) x = x #else # define INITIALIZED(x) x #endif And suppose we remove -Winit-self from GCC_DEBUG_FLAGS, and replace existing code "int local; INITIALIZE(local);" with "int INITIALIZED(local);" to pacify GCC when we know that "local" cannot be used uninitialized but GCC doesn't deduce this. The problem with this approach is that if there is buggy code somewhere else that says "int local2 = local2;", GCC won't warn about it.
because of the halting problem, it's not valid to say that a warning is a sign of an inferior compiler
It's a quality-of-implementation issue, and it's fair to say that some compilers are better than others in this area. It's true that because of the halting problem, no compiler can do a perfect job: for any compiler X that you can build, someone else can build a compiler Y that is better than X in this area. When I wrote "an inferior compiler", I meant "a compiler inferior to recent GCC", not "a compiler inferior to a perfect compiler".