[Bug c++/61489] Wrong warning with -Wmissing-field-initializers.
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jun 12 18:54:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61489
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Deniz Bahadir from comment #0)
> When compiling the following code (in C++11 mode) with
> -Wmissing-field-initializers then almost all attempts to initialize
> "sockaddr_in" result in compiler-warnings about uninitialized field-members.
> However, as far as I understand, almost all initializations should be fine
> and zero-initialize (?) all struct-members and the compiler-warnings should
> therefore not occur.
But that's exactly the situation -Wmissing-field-initializers is designed to
warn about, so the warning is not wrong.
>
>
> <code>
> // Compile this code with: g++ -std=c++11 -Wmissing-field-initializers
> bug.cpp
>
> #include <netinet/in.h>
>
> int main()
> {
> struct sockaddr_in addr0; // No warning. But really
> zero-initialized?
No, uninitialized.
> //struct sockaddr_in addr1(); // No warning, but a function-declaration.
> struct sockaddr_in addr2 = {}; // In C++: Warning about all members.
I think it shouldn't warn for an empty braced-init-list, as that has special
meaning in C++11.
> // In C: Warning about first member.
It's not valid in C, you always need at least one initializer.
> struct sockaddr_in addr3 = {0}; // In C++: Warning about all members
> // except the first one.
> struct sockaddr_in addr4 = {0,}; // Same here.
That's exactly what the warning is designed to warn about.
> #ifdef __cplusplus
> struct sockaddr_in addr5 = sockaddr_in(); // No warning and (probably)
> // zero-initialized.
Definitely zero-initialized.
More information about the Gcc-bugs
mailing list