[igt-dev] tests: add missing braces around initializer

Carlos Santa carlos.santa at intel.com
Thu Jul 23 15:29:30 UTC 2020


On Wed, 2020-07-22 at 10:56 +0300, Petri Latvala wrote:
> 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?

It was with gcc 4.9, googling around this issue seems to be a bug
within the toolchain itself: 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119 but it looks like
the fix was never backported.

Carlos

> 
> 



More information about the igt-dev mailing list