-Wmissing-field-initializers

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?

Howard

It seems to me a little hard to separate this case from the general
case the warning is trying to implement - except that, yes, this seems
like a fairly common idiom even if it's no more useful than {}.

But someone had the same question about GCC with a more in-depth
rationalization (apparently {0} has special behavior in C99 that
differs from {}) & so they changed their behavior do fulfill your
request ( http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36750 ). We
should probably do the same, I suppose.

- David

-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.

John.

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

But using {}, as you suggest, gives:

warning: use of GNU empty initializer extension [-pedantic,-Wgnu]

One seems trapped between one warning or the other.

Only in C; C++ allows {}.

-Eli

-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.

But using {}, as you suggest, gives:

warning: use of GNU empty initializer extension [-pedantic,-Wgnu]

This is one of my consistent blind spots; it surprises me every single time.
Although we were talking about C++ here, where {} is permitted.

One seems trapped between one warning or the other.

I agree that something should probably be done for the C case.
If that means white-listing {0}, okay. I'd still prefer to only do so in C,
since the better option is available in C++.

John.