Skip to content

Commit d0cd064

Browse files
committed
Add regression tests for enum underlying type specification feature
1 parent 4ded255 commit d0cd064

File tree

6 files changed

+85
-0
lines changed

6 files changed

+85
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <assert.h>
2+
3+
enum enum1
4+
{
5+
E1
6+
};
7+
8+
enum enum2 : signed char
9+
{
10+
E2
11+
};
12+
13+
typedef signed char signed_char_t;
14+
15+
enum enum3 : signed_char_t
16+
{
17+
E3
18+
};
19+
20+
int main()
21+
{
22+
assert(sizeof(int) != sizeof(signed char));
23+
assert(sizeof(enum enum1) == sizeof(int));
24+
assert(sizeof(enum enum2) == sizeof(signed char));
25+
assert(sizeof(enum enum3) == sizeof(signed char));
26+
27+
enum enum2 e2 = 0xff;
28+
assert(e2 == -1);
29+
30+
enum enum3 e3 = 0xff;
31+
assert(e3 == -1);
32+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Checks that the underlying type specification of an enum is correctly
11+
interpreted, i.e., the size and signedness of the integral type chosen for the
12+
enum is the one specified. Also checks that it works with typedef'd types.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <assert.h>
2+
3+
enum enum1 : unsigned char
4+
{
5+
E1 = 256
6+
};
7+
8+
int main()
9+
{
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=6$
5+
^SIGNAL=0$
6+
^file main.c line \d+: enumerator value is not representable in the underlying type 'unsigned_char'$
7+
--
8+
^warning: ignoring
9+
--
10+
Checks that values that cannot be represented by the specified underlying type
11+
are rejected
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <assert.h>
2+
3+
enum enum1 : float
4+
{
5+
E1
6+
};
7+
8+
int main()
9+
{
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=6$
5+
^SIGNAL=0$
6+
^file main.c line \d+: non-integral type 'float' is an invalid underlying type$
7+
--
8+
^warning: ignoring
9+
--
10+
Checks that non-integral types are rejected

0 commit comments

Comments
 (0)