Skip to content

Commit a4b5abb

Browse files
danpoeChristopher Wagner
authored and
Christopher Wagner
committed
Allow multi word types and typedef'd names as underlying enum types
Our previous attempt only worked with names like `short` or `unsigned`, but not with e.g. `unsigned short` or `uint32_t`. This patch rectifies that. Note that unlike clang we currently don't allow CV qualifiers for underlying types. Since these are ignored by clang anyway, we don't expect to see too much code in the wild making use of that feature however.
1 parent 09d5c3b commit a4b5abb

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
typedef unsigned short USHORT;
2+
3+
enum A : USHORT
4+
{
5+
AV
6+
};
7+
enum B : unsigned short
8+
{
9+
BV
10+
};
11+
enum C : signed long long
12+
{
13+
CV
14+
};
15+
16+
int main(void)
17+
{
18+
return 0;
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
test.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^PARSING ERROR$
8+
--
9+
A previous attempt to allow underlying type specifications didn't allow typedef
10+
names or multi word types (e.g. unsigned int). We still don't actually fully
11+
apply the underlying type to the enum, but this at least lets us use parse code
12+
that uses this feature.

src/ansi-c/parser.y

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,13 +1837,21 @@ enum_name:
18371837
}
18381838
;
18391839

1840+
basic_type_name_list:
1841+
basic_type_name
1842+
| basic_type_name_list basic_type_name
1843+
1844+
enum_underlying_type:
1845+
basic_type_name_list
1846+
| typedef_name
1847+
18401848
enum_underlying_type_opt:
18411849
/* empty */
18421850
{
18431851
init($$);
18441852
parser_stack($$).make_nil();
18451853
}
1846-
| ':' basic_type_name
1854+
| ':' enum_underlying_type
18471855
{
18481856
$$=$2;
18491857
}

0 commit comments

Comments
 (0)