[cfe-dev] -Wmissing-field-initializers

Howard Hinnant hhinnant at apple.com
Mon Feb 20 12:24:48 PST 2012


On Feb 20, 2012, at 3:16 PM, John McCall wrote:

> On Feb 20, 2012, at 8:48 AM, Howard Hinnant wrote:
>> I'm getting the following warning on building libc++:
>> 
>> ../src/locale.cpp:4554:14: warning: missing field 'tm_min' initializer [-Wmissing-field-initializers]
>>   tm t = {0};
>>            ^
>> 1 warning generated.
>> 
>> I know what the warning is saying.  My question is why?  I presume tm_min is getting initialized to 0 as intended.  The above is pretty standard fare (I thought) for zero-initializing an aggregate.  Isn't this warning a little too chatty?
> 
> -Wmissing-field-initializers does have a special case for intentional uses of the language's default-zero-initialization rules.  However, that special case is spelled {}, not {0}.  If you feel that this is a really common idiom for zero-initialization, we could also add it, but I'd really prefer not to, because it neuters -Wmissing-field-initializers on an interesting class of bugs.
> 
> I acknowledge the argument for {0} being a more explicit "I want to zero-initialize this whole thing", but I don't actually agree.  Neither {} nor {0} is being used for its obvious, literal meaning ("there is nothing to initialize here" and "there is one thing to initialize here, and I want it to be zero", respectively).  Both expect the code-reader to understand the language's implicit-initialization rules. The first, however, is pretty obviously not the programmer's intended meaning when used to initialize an object that's known to carry information.

I'm content with:

#pragma clang diagnostic ignored "-Wmissing-field-initializers"

for libc++ code.  Though I do suspect that this issue will come again with someone else.

Howard




More information about the cfe-dev mailing list