Menu

#936 initializing type containing anonymous union can cause gcc warning

open
nobody
None
compiler
2021-09-16
2021-06-27
No

A type with a nested union appears to lose some information about where to put the initializing braces in the C emitter. Noticed this only on static initializers (shared. and no issue on gas/gas64 backends.

type T
    a as integer
    union
        b as integer
        c as byte
    end union
end type

dim shared x as const T = ( 1, (2) )
print x.c

/' gcc output
struct.c:23:24: warning: missing braces around initializer [-Wmissing-braces]
   23 | static struct $1T X$ = { 1, 2 };
      |                        ^
      |                             { }
'/

When the union is named, the gcc warning does not appear:

union U
    b as integer
    c as byte
end union

type T
    a as integer
    d as U
end type

dim shared x as const T = ( 1, (2) )
print x.d.c

Discussion

  • fxm (freebasic.net)

    Same problem with anonymous type:

    union U
        type
            a as integer
            b as byte
        end type
        c as integer
    end union
    
    dim shared x as const U = ( 1, 2)
    print x.a, x.b
    
     
  • TeeEmCee

    TeeEmCee - 2021-09-16

    This has been around for years. I know that GCC 9+ throws the warning, but don't know if GCC 8 does.

     

Log in to post a comment.