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

Ville Syrjälä ville.syrjala at linux.intel.com
Wed Jul 22 11:45:04 UTC 2020


On Wed, Jul 22, 2020 at 10:56:03AM +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,

It works just fine. We use it extensively all over.

> 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
> _______________________________________________
> igt-dev mailing list
> igt-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev

-- 
Ville Syrjälä
Intel


More information about the igt-dev mailing list