Module Name: src Committed By: rillig Date: Tue Mar 9 23:09:48 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_130.c msg_130.exp Log Message: tests/lint: add tests for comparison between unnamed enums Since unnamed enum types cannot be used in type casts, there is no sensible way that this type mismatch could be resolved, without changing the definition of the enum type itself, but that may be in a non-modifiable header. Therefore, comparisons with enum constants of unnamed types cannot be sensibly warned about. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_130.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_130.exp Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/msg_130.c diff -u src/tests/usr.bin/xlint/lint1/msg_130.c:1.8 src/tests/usr.bin/xlint/lint1/msg_130.c:1.9 --- src/tests/usr.bin/xlint/lint1/msg_130.c:1.8 Fri Mar 5 17:10:06 2021 +++ src/tests/usr.bin/xlint/lint1/msg_130.c Tue Mar 9 23:09:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_130.c,v 1.8 2021/03/05 17:10:06 rillig Exp $ */ +/* $NetBSD: msg_130.c,v 1.9 2021/03/09 23:09:48 rillig Exp $ */ # 3 "msg_130.c" // Test for message: enum type mismatch: '%s' '%s' '%s' [130] @@ -53,3 +53,40 @@ switch_example(enum color c) break; } } + +/* + * Unnamed enum types can be used as a container for constants, especially + * since in C90 and C99, even after the declaration 'static const int x = 3', + * 'x' is not a constant expression. + */ +enum { + sizeof_int = sizeof(int), + sizeof_long = sizeof(long) +}; + +enum { + sizeof_uint = sizeof(unsigned int) +}; + +int +enum_constant_from_unnamed_type(int x) +{ + switch (x) { + case sizeof_int: /* expect: 130 *//* FIXME */ + return 1; + case sizeof_long: /* expect: 130 *//* FIXME */ + return 2; + default: + break; + } + + if (x == sizeof_int) + return 4; + if (x > sizeof_int) + return 5; + + if (sizeof_int == sizeof_uint) /* expect: 130 *//* FIXME */ + return 6; + + return 0; +} Index: src/tests/usr.bin/xlint/lint1/msg_130.exp diff -u src/tests/usr.bin/xlint/lint1/msg_130.exp:1.6 src/tests/usr.bin/xlint/lint1/msg_130.exp:1.7 --- src/tests/usr.bin/xlint/lint1/msg_130.exp:1.6 Fri Mar 5 17:10:06 2021 +++ src/tests/usr.bin/xlint/lint1/msg_130.exp Tue Mar 9 23:09:48 2021 @@ -4,3 +4,6 @@ msg_130.c(32): warning: enum type mismat msg_130.c(47): warning: enum type mismatch: 'enum color' '==' 'enum daytime' [130] msg_130.c(48): warning: enum type mismatch: 'enum color' '==' 'enum size' [130] msg_130.c(49): warning: enum type mismatch: 'enum color' '==' 'int' [130] +msg_130.c(75): warning: enum type mismatch: 'int' '==' 'enum <unnamed>' [130] +msg_130.c(77): warning: enum type mismatch: 'int' '==' 'enum <unnamed>' [130] +msg_130.c(88): warning: enum type mismatch: 'enum <unnamed>' '==' 'enum <unnamed>' [130]