On 9/6/19 8:44 AM, Eric Blake wrote: > On 9/6/19 8:24 AM, Philippe Mathieu-Daudé wrote: > >>>>> static const MemoryRegionOps notdirty_mem_ops = { >>>>> .write = notdirty_mem_write, >>>>> - .valid.accepts = notdirty_mem_accepts, >>>>> .endianness = DEVICE_NATIVE_ENDIAN, >>>>> .valid = { >>>>> .min_access_size = 1, >>>>> .max_access_size = 8, >>>>> .unaligned = false, >>>>> + .accepts = notdirty_mem_accepts, >>>> >>>> I'm surprised the compiler doesn't emit any warning... >>> >>> Same here.
Actually, I just played with -Woverride-init in gcc 9.2.1 (and clang's comparable -Winitializer-overrides, which we intentionally disable during configure), and they come pretty close - both compilers DO flag when an implicit zero-initialization due to partial ={} overrides an earlier initialization. But sadly, they also warn when one specific init of a smaller subobject overrides another earlier specific init of a larger subobject such as an array range operator. So qobject/json-lexer.c and others fail to compile under the existing warning option, which is why we disable it during configure (clang has it as part of -Wall; gcc only has it as part of -Wextra which we do not use). In researching further, I see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24010#c4 which explains why -Woverride-init is NOT part of gcc's -Wall, precisely because of our range pre-initialization usage. So I filed: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91688 seeing if the gcc devs would consider splitting into -Woverride-init=[12], where 1 only flags a larger subobject overriding an earlier smaller one (would have caught our bug) and 2 flags an equal-size or smaller subobject overriding an earlier large one (which we would not use, because we rely on that for range pre-initialization). -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org