| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: msg_130.c,v 1.13 2021/04/02 13:16:38 rillig Exp $ */ | | 1 | /* $NetBSD: msg_130.c,v 1.14 2021/05/25 19:04:07 rillig Exp $ */ |
2 | # 3 "msg_130.c" | | 2 | # 3 "msg_130.c" |
3 | | | 3 | |
4 | // Test for message: enum type mismatch: '%s' '%s' '%s' [130] | | 4 | // Test for message: enum type mismatch: '%s' '%s' '%s' [130] |
5 | | | 5 | |
6 | /* See also msg_241.c, which covers unusual operators on enums. */ | | 6 | /* See also msg_241.c, which covers unusual operators on enums. */ |
7 | | | 7 | |
8 | enum color { | | 8 | enum color { |
9 | RED = 1 << 0, | | 9 | RED = 1 << 0, |
10 | GREEN = 1 << 1, | | 10 | GREEN = 1 << 1, |
11 | BLUE = 1 << 2 | | 11 | BLUE = 1 << 2 |
12 | }; | | 12 | }; |
13 | | | 13 | |
14 | enum size { | | 14 | enum size { |
| @@ -51,41 +51,41 @@ switch_example(enum color c) | | | @@ -51,41 +51,41 @@ switch_example(enum color c) |
51 | break; | | 51 | break; |
52 | default: | | 52 | default: |
53 | break; | | 53 | break; |
54 | } | | 54 | } |
55 | } | | 55 | } |
56 | | | 56 | |
57 | /* | | 57 | /* |
58 | * Unnamed enum types can be used as a container for constants, especially | | 58 | * Unnamed enum types can be used as a container for constants, especially |
59 | * since in C90 and C99, even after the declaration 'static const int x = 3', | | 59 | * since in C90 and C99, even after the declaration 'static const int x = 3', |
60 | * 'x' is not a constant expression. | | 60 | * 'x' is not a constant expression. |
61 | */ | | 61 | */ |
62 | enum { | | 62 | enum { |
63 | sizeof_int = sizeof(int), | | 63 | sizeof_int = sizeof(int), |
64 | sizeof_long = sizeof(long) | | 64 | sizeof_short = sizeof(short) |
65 | }; | | 65 | }; |
66 | | | 66 | |
67 | enum { | | 67 | enum { |
68 | sizeof_uint = sizeof(unsigned int) | | 68 | sizeof_uint = sizeof(unsigned int) |
69 | }; | | 69 | }; |
70 | | | 70 | |
71 | int | | 71 | int |
72 | enum_constant_from_unnamed_type(int x) | | 72 | enum_constant_from_unnamed_type(int x) |
73 | { | | 73 | { |
74 | /* using an enum constant as constant-expression */ | | 74 | /* using an enum constant as constant-expression */ |
75 | switch (x) { | | 75 | switch (x) { |
76 | case sizeof_int: | | 76 | case sizeof_int: |
77 | return 1; | | 77 | return 1; |
78 | case sizeof_long: | | 78 | case sizeof_short: |
79 | return 2; | | 79 | return 2; |
80 | default: | | 80 | default: |
81 | break; | | 81 | break; |
82 | } | | 82 | } |
83 | | | 83 | |
84 | if (x == sizeof_int) | | 84 | if (x == sizeof_int) |
85 | return 4; | | 85 | return 4; |
86 | if (x > sizeof_int) | | 86 | if (x > sizeof_int) |
87 | return 5; | | 87 | return 5; |
88 | | | 88 | |
89 | if (sizeof_int == sizeof_uint) /* expect: 130 *//* FIXME */ | | 89 | if (sizeof_int == sizeof_uint) /* expect: 130 *//* FIXME */ |
90 | return 6; | | 90 | return 6; |
91 | | | 91 | |