[Mesa-dev] [PATCH v3 0/3] Fix missing initializer errors in generated tables

Brian Paul brianp at vmware.com
Mon Jun 12 14:13:03 UTC 2017


Benedikt,

We normally prefix the first line of the git commit message with a 
prefix to indicate the module effected.  So in this case, you might use 
"amd: Fix missing..." or "r600: Fix missing".  You can use git log to 
get an idea.

-Brian

On 06/11/2017 11:17 AM, Benedikt Schemmer wrote:
> This series aims to fix hundreds of missing initializer warnings in generated header files
> when compiling with -Wextra
>
> V1: Fix the old fashioned way by adding 0s where needed
> V2: switch to designated initializers (Emil), didnt send
> V3: add some layout so its easier to read and create a new version for vk that
>      just uses {0} instead of {0, 0, 0, 0, 0} (same thing, less zeros)
>
> ---
>
> Because this generated such unexpected controversy and out of curiosity i wrote a little
> test program to show the problem. Compile with -Wextra.
> There is no init code generated for any variant on any compiler i tested.
>
> gcc version 5.4.1 20170304 (Ubuntu 5.4.1-8ubuntu1)
> gcc version 6.3.0 20170406 (Ubuntu 6.3.0-12ubuntu2)
> gcc version 7.0.1 20170407 (experimental) [trunk revision 246759] (Ubuntu 7-20170407-0ubuntu2)
> clang version 4.0.0-1ubuntu1 (tags/RELEASE_400/rc1)
> clang version 5.0.0-svn305158-0~z~padoka0 (trunk)
> MSVC Compiler Version 19.00.24210
>
> ---
>
> struct s {
>     int a;
>     int b;
>     int c;
>     int d;
>     int e;
> };
>
> static const struct s str1 = {};           // gcc 5/6/7, clang 4/5 accept this without warning, MSVC2013 doesnt compile
> (not Standard, will generate a warning with -Wpendantic, much prettier however)
> static const struct s str2 = {0};          // clang 4/5 generate a warning here (although ANSI Standard)
> static const struct s str3 = {0,};         // clang 4/5 generate a warning here (although ANSI Standard)
> static const struct s str4 = {1,2,3};      // gcc 5/6/7, clang 4/5 generate a warning here
> static const struct s str5 = {1,2,3,};     // gcc 5/6/7, clang 4/5 generate a warning here
> static const struct s str6 = {1,2,3,0,0};  // this is fine with all compilers
> static const struct s str7 = {.a = 1, .b = 2, .c = 3}; // this might not compile on MSVC <2013 but couldnt test
>
> int main() {
>     return 0;
> }
>
> ---
>
> This is what Rust does:
>
> ---
>
> #![allow(unused_variables)]
> #![allow(dead_code)]
>
> #[derive(Default)]
> struct Test {
>     a: i32,
>     b: i32,
>     c: i32,
>     d: i32,
>     e: i32
> }
>
> fn main() {
> //all of these wont work
> //    let t1 = Test {};
> //    let t2 = Test {0};
> //    let t3 = Test {0,};
> //    let t3b= Test {..}; would be very cool
> //    let t4 = Test {1,2,3};
> //    let t5 = Test {1,2,3,};
> //    let t6 = Test {1,2,3,0,0};
> //    let t7 = Test {a: 1, b: 1};
> //    let t8 = Test {a: 1, b: 1, ..}; would be cool
>
> //only this is legal in rust
>      let t9: Test = Default::default();
>      let t10 = Test {..Default::default()};
>      let t11 = Test {a: 1, b: 1, ..Default::default()};
>      let t12 = Test {a: 1, b: 1, c: 1, d: 1, e: 1};
>
>      println!("Hello, world!");
> }
>
> ---
>
> So in the end I followed Emils suggestion of designated initializers for partial initialization,
> to make it explicit and get rid of the warnings.
>
> Please kindly review and push.
>
> Thanks,
> Benedikt
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>



More information about the mesa-dev mailing list