Skip to content

Commit

Permalink
Fix detection of anonymous bit fields in a structure
Browse files Browse the repository at this point in the history
  • Loading branch information
bengardner committed Nov 24, 2010
1 parent bda365f commit ef6ccba
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/align.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ static chunk_t *align_var_def_brace(chunk_t *start, int span, int *p_nl_count)
}
did_this_line = true;
}
if (pc->type == CT_BIT_COLON)
else if (pc->type == CT_BIT_COLON)
{
if (!did_this_line)
{
Expand Down
10 changes: 7 additions & 3 deletions src/combine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,8 @@ void combine_labels(void)
}
else if (cur->type == CT_WORD)
{
if (chunk_is_newline(prev))
tmp = chunk_get_next_nc(next, CNAV_PREPROC);
if (chunk_is_newline(prev) && ((tmp == NULL) || (tmp->type != CT_NUMBER)))
{
cur->type = CT_LABEL;
next->type = CT_LABEL_COLON;
Expand Down Expand Up @@ -1873,8 +1874,11 @@ void combine_labels(void)
{
/* ignore it, as it is inside a paren */
}
else if ((cur->type == CT_TYPE) ||
(cur->type == CT_ENUM) ||
else if (cur->type == CT_TYPE)
{
next->type = CT_BIT_COLON;
}
else if ((cur->type == CT_ENUM) ||
(cur->type == CT_PRIVATE) ||
(cur->type == CT_QUALIFIER) ||
(cur->parent_type == CT_ALIGN))
Expand Down
8 changes: 7 additions & 1 deletion tests/input/c/align-var.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ struct foo2
unsigned int a : 1;
unsigned int bcd : 3;
unsigned int ef : 2;
unsigned int gh : 2;
unsigned int : 2;

unsigned short more;

int fields;
};

typedef struct {
bitfld a : 8;
bitfld b : 16;
bitfld : 8;
} type_t;

struct foo { int a; char *b };

static int idx;
Expand Down
9 changes: 8 additions & 1 deletion tests/output/c/00402-align-var.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ struct foo2
unsigned int a : 1;
unsigned int bcd : 3;
unsigned int ef : 2;
unsigned int gh : 2;
unsigned int : 2;

unsigned short more;

int fields;
};

typedef struct
{
bitfld a : 8;
bitfld b : 16;
bitfld : 8;
} type_t;

struct foo { int a; char *b };

static int idx;
Expand Down
9 changes: 8 additions & 1 deletion tests/output/c/00403-align-var.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ struct foo2
unsigned int a : 1;
unsigned int bcd : 3;
unsigned int ef : 2;
unsigned int gh : 2;
unsigned int : 2;

unsigned short more;

int fields;
};

typedef struct
{
bitfld a : 8;
bitfld b : 16;
bitfld : 8;
} type_t;

struct foo { int a; char *b };

static int idx;
Expand Down
9 changes: 8 additions & 1 deletion tests/output/c/00404-align-var.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ struct foo2
unsigned int a : 1;
unsigned int bcd : 3;
unsigned int ef : 2;
unsigned int gh : 2;
unsigned int : 2;

unsigned short more;

int fields;
};

typedef struct
{
bitfld a : 8;
bitfld b : 16;
bitfld : 8;
} type_t;

struct foo { int a; char *b };

static int idx;
Expand Down

0 comments on commit ef6ccba

Please sign in to comment.