Unable to initialize struct with a struct

Started by neo313, June 06, 2014, 11:44:22 PM

Previous topic - Next topic

neo313

This bug is present with any optimization level and both c99 or c11 standard mode, using: 8.00.11 RC#4, 32bit , Windows 7

error text: Invalid initialization type; expected 'int' but found 'struct A'.


#include <stdio.h>

struct A
{
    int i;
} ;

struct B
{
   struct A st ;
} ;

int main( void )
{
    struct A a = { 12345 } ;
    struct B b = { a };    //Invalid initialization type; expected 'int' but found 'struct A'.

    printf("%d" , b.st.i ) ;

    return 0;
}


Same error happens if struct is initialized using designated initializers struct B b = { .st =  { a } }; or struct B b = { .st =  a };

This is surely allowed according to C Standard. Reference: 6.7.9, paragraph 13

Ideone example compiles in strict C99 mode:
https://ideone.com/FWSqak

Relevant bug reports:
https://stackoverflow.com/questions/23707402/initializing-struct-within-another-struct-using-designated-initializer-causes-co
http://stackoverflow.com/questions/24090739/possible-compiler-bug-in-msvc12-vs2013-with-designated-initializer#24090739

Pelle

A known, long standing, bug. This case is hard to fix in this compiler. Will take time...
/Pelle

neo313

#2
Thanks, I didn't encounter this myself; I still reported it just to be sure.