[Bug c/36688] New: Incorrect struct assignments with nested const initializers

holger dot hopp at sap dot com gcc-bugzilla@gcc.gnu.org
Tue Jul 1 14:04:00 GMT 2008


g++ 4.3 and higher produces incorrect struct assignments with nested
constant initializers. In the example, the assignment x = init_x
initializes the struct with zero's, not with {{1,2,3},0}.

gcc versions:
  gcc 4.3.2 (svn, 2008/07/01, rev. 137317)
  gcc 4.4.0 (svn, 2008/06/24)

  gcc 3.3.3 and gcc 4.1.2 (SuSE) are running fine.

systems:
  x86_64, ia64 (probably platform independent)

command line:
  g++ -O0 t.c  (occurs with and without optimizations)


preprocessed file:

typedef long unsigned int size_t;

extern "C" int memcmp (__const void *__s1, __const void *__s2, size_t __n)
     throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));

typedef struct
{
  long long a;
  long long b;
  long long c;
} t_bar;


typedef struct
{
  t_bar g;
  long long free[12];
}
t_foo;


static const t_bar init_y = {1,2,3};
static const t_foo init_x = {init_y,0};

int main ()
{
  t_foo x = init_x;
  return memcmp (&x, &init_x, sizeof(t_foo));
}


-- 
           Summary: Incorrect struct assignments with nested const
                    initializers
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: holger dot hopp at sap dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36688



More information about the Gcc-bugs mailing list