[igt-dev] tests: add missing braces around initializer
Petri Latvala
petri.latvala at intel.com
Wed Jul 22 07:56:03 UTC 2020
On Tue, Jul 21, 2020 at 11:15:21AM -0700, Carlos Santa wrote:
> In some sandboxes the toolchain complains about missing braces
> around initializer, however, adding an extra pair of braces
> fixes it, see below:
>
> ../tests/kms_plane_cursor.c: In function '__real_main_302':
> ../tests/kms_plane_cursor.c:305:2 error: missing braces around initializer [-Werror=missing-braces]
> data_t data = { 0 };
>
Argh, gcc.
C++ supports initializing with empty braces ( data_t data = {}; ) and
C doesn't, leaving only the commonly used { 0 } idiom to mean "I just
want to zero-initialize this object, don't care about the
structure". Even better, due to the brace elision clause in the spec,
that construct is fully defined and means exactly fully
zero-initializing the aggregate object regardless of its structure.
I could agree with this change if the initialization used non-zero
values but just adding braces to make the compiler believe you really
meant this...
I wonder if playing around with -Wmissing-initializer
-Wno-missing-braces lets us leave the code as { 0 } for elegance,
while still get a warning for actual incorrect use...
Which version of gcc was this on?
--
Petri Latvala
More information about the igt-dev
mailing list