Clang will warn on `{0}` as -Wmissing-field-initializers even in C code. The language provides this to explicitly say "initialize everything to zero". Some discussion here: http://clang-developers.42468.n3.nabble.com/Wmissing-field-initializers-td3761260.html I'm fine with John's solution of only relaxing this for C code.
Same (fixed) bug in gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119 Related bug in POSIX: http://austingroupbugs.net/view.php?id=918 And I think this bug should be fixed even in C++, just because we should have some uniform way to initialize addrinfo and mbstate_t in both C and C++
This is also tracked as rdar://problem/24498474
Here's an example of false positive in the real world: /home/emaisin/src/binutils-gdb/bfd/elfnn-riscv.c:3145:36: error: missing field 'hi_addend' initializer [-Werror,-Wmissing-field-initializers] riscv_pcgp_hi_reloc hi_reloc = {0}; ^ https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elfnn-riscv.c;h=47d2c477036c909c799b7f452d4acba2b8145977;hb=HEAD#l3145
Here's an additional example of a false-positive I encountered in one of my own projects (when tested on Clang v5.0): /home/travis/build/saxbophone/libsxbp/sxbp/begin_figure.c:150:34: error: missing field 'y' initializer [-Werror,-Wmissing-field-initializers] sxbp_co_ord_t location = { 0 }; // where the end of the last line is ^ /home/travis/build/saxbophone/libsxbp/sxbp/begin_figure.c:151:32: error: missing field 'x_max' initializer [-Werror,-Wmissing-field-initializers] sxbp_bounds_t bounds = { 0 }; // the bounds of the line traced so far The code that triggers the warning can be found at: https://github.com/saxbophone/libsxbp/blob/7e68075/sxbp/begin_figure.c#L150-L151 And a failing build showing that the bug occurs in Clang v5.0 but not in GCC v5.4: https://travis-ci.org/saxbophone/libsxbp/builds/326179760
This has been fixed with r314499 (https://reviews.llvm.org/D28148) which ended up in Clang 6 (and by extension, Xcode 10). As a workaround, include -Wno-missing-field-initializers for older compilers: - GCC < 4.7 (CMAKE_C_COMPILER_ID "GNU") - Clang < 6.0 - AppleClang < 10.0
*** Bug 32156 has been marked as a duplicate of this bug. ***