https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71552

--- Comment #2 from Mason <mpeg.blue at free dot fr> ---
Martin,

Please reconsider this bug's resolution.

In my opinion, "conversion of integers to pointers" is a red herring.

This test case (double vs double ptr) triggers the same confusing error:

struct foo { double *p; };
static double d = 0.5;
struct foo bar = { d }; /*** should be &d ***/

$ gcc-6 -c qoi.c
qoi.c:3:20: error: initializer element is not constant
 struct foo bar = { d }; /*** should be &d ***/
                    ^
qoi.c:3:20: note: (near initialization for 'bar.p')


My actual code was, in fact, closer to this:

struct xxx { void *p; int a,b,c,d; double x,y; };
struct foo { struct xxx *p; int e,f,g; };
static struct xxx s = { 0 };
struct foo bar = { s }; /*** should be &s ***/

$ gcc-6 -c qoi.c
qoi.c:4:20: error: initializer element is not constant
 struct foo bar = { s }; /*** should be &s ***/
                    ^
qoi.c:4:20: note: (near initialization for 'bar.p')


In fact, "simple" incorrect initialization triggers the expected error:

struct xxx { void *p; int a,b,c,d; double x,y; };
struct foo { struct xxx *p; int e,f,g; };
static struct xxx s = { 0 };
void func(void)
{
        struct xxx *p = s;
}

$ gcc-6 -c qoi.c
qoi.c: In function 'func':
qoi.c:6:18: error:
incompatible types when initializing type 'struct xxx *' using type 'struct
xxx'
  struct xxx *p = s;
                  ^

Couldn't struct member initialization be handled the same way?

Regards.

Reply via email to