Tue May 25 19:04:07 2021 UTC ()
tests/lint: make test 130 platform-independent

On 32-bit platforms such as i386 and sparc, sizeof(int) == sizeof(long),
which produced an additional unintended lint error message:

msg_130.c(78): error: duplicate case in switch: 4 [199]


(rillig)
diff -r1.13 -r1.14 src/tests/usr.bin/xlint/lint1/msg_130.c

cvs diff -r1.13 -r1.14 src/tests/usr.bin/xlint/lint1/msg_130.c (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/msg_130.c 2021/04/02 13:16:38 1.13
+++ src/tests/usr.bin/xlint/lint1/msg_130.c 2021/05/25 19:04:07 1.14
@@ -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
8enum color { 8enum 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
14enum size { 14enum 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 */
62enum { 62enum {
63 sizeof_int = sizeof(int), 63 sizeof_int = sizeof(int),
64 sizeof_long = sizeof(long) 64 sizeof_short = sizeof(short)
65}; 65};
66 66
67enum { 67enum {
68 sizeof_uint = sizeof(unsigned int) 68 sizeof_uint = sizeof(unsigned int)
69}; 69};
70 70
71int 71int
72enum_constant_from_unnamed_type(int x) 72enum_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