Skip to content

Fix sizeof of structs with a trailing unbound array #574

@robertoraggi

Description

@robertoraggi

Expected

struct X_char {
  char i;
  char data[];
};

struct X_short {
  char i;
  short data[];
};


static_assert(sizeof(struct X_char) == 1);
static_assert(alignof(struct X_char) == 1);

static_assert(sizeof(struct X_short) == 2);
static_assert(alignof(struct X_short) == alignof(short));
cxx -xc x.c  -fcheck
x.c:2:8: error: size of incomplete type 'char data[]'
struct X_char {
       ^
x.c:7:8: error: size of incomplete type 'short data[]'
struct X_short {
       ^
x.c:13:1: error: static assert failed
static_assert(sizeof(struct X_char) == 1);
^
x.c:16:1: error: static assert failed
static_assert(sizeof(struct X_short) == 2);
^
x.c:17:1: error: static assert failed
static_assert(alignof(struct X_short) == alignof(short));
^

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions