From 9a83ddef776320edc8809c13f5316b82a3429bde Mon Sep 17 00:00:00 2001 From: rillig Date: Sat, 2 Jan 2021 15:55:54 +0000 Subject: [PATCH] lint: add test for message 35: illegal bit-field type Bug: _Bool is not accepted as a bit-field, but it should be. Bug: lint aborts in a controlled manner with message "common/tyname.c, 190: tspec_name(0)" when it sees a declaration of a _Complex bit-field. (Not that a _Complex bit-field would make any sense.) --- tests/usr.bin/xlint/lint1/msg_035.c | 52 +++++++++++++++++++++++++-- tests/usr.bin/xlint/lint1/msg_035.exp | 19 +++++++++- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/tests/usr.bin/xlint/lint1/msg_035.c b/tests/usr.bin/xlint/lint1/msg_035.c index f3ef1ee29df9..85898fa08681 100644 --- a/tests/usr.bin/xlint/lint1/msg_035.c +++ b/tests/usr.bin/xlint/lint1/msg_035.c @@ -1,7 +1,53 @@ -/* $NetBSD: msg_035.c,v 1.1 2021/01/02 10:22:43 rillig Exp $ */ +/* $NetBSD: msg_035.c,v 1.2 2021/01/02 15:55:54 rillig Exp $ */ # 3 "msg_035.c" // Test for message: illegal bit-field type [35] -TODO: "Add example code that triggers the above message." -TODO: "Add example code that almost triggers the above message." +typedef struct { + int dummy; +} example_struct; + +typedef union { + int dummy; +} example_union; + +typedef enum { + NO, YES +} example_enum; + +typedef void (example_function)(int, const char *); + +/* Try all types from tspec_t. */ +struct example { + signed signed_flag: 1; + unsigned unsigned_flag: 1; + _Bool boolean_flag: 1; // FIXME: allowed since C99 6.7.2.1p5 + char char_flag: 1; + signed char signed_char_flag: 1; + unsigned char unsigned_char_flag: 1; + short short_flag: 1; + unsigned short unsigned_short_flag: 1; + int int_flag: 1; + unsigned int unsigned_int_flag: 1; + long long_flag: 1; + unsigned long unsigned_long_flag: 1; + long long long_long_flag: 1; + unsigned long long unsigned_long_long_flag: 1; + /* __int128_t omitted since it is not always defined */ + /* __uint128_t omitted since it is not always defined */ + float float_flag: 1; + double double_flag: 1; + long double long_double_flag: 1; + void void_flag: 1; + example_struct struct_flag: 1; + example_union union_flag: 1; + example_enum enum_flag: 1; + void *pointer_flag: 1; + unsigned int array_flag[4]: 1; + example_function function_flag: 1; +// FIXME: aborts: _Complex complex_flag: 1; + _Complex complex_flag: 1; + float _Complex float_complex_flag: 1; + double _Complex double_complex_flag: 1; + long double _Complex long_double_complex_flag: 1; +}; diff --git a/tests/usr.bin/xlint/lint1/msg_035.exp b/tests/usr.bin/xlint/lint1/msg_035.exp index 0378e5ac8ba2..666e272e086b 100644 --- a/tests/usr.bin/xlint/lint1/msg_035.exp +++ b/tests/usr.bin/xlint/lint1/msg_035.exp @@ -1 +1,18 @@ -msg_035.c(6): syntax error ':' [249] +msg_035.c(24): warning: illegal bit-field type [35] +msg_035.c(32): warning: illegal bit-field type [35] +msg_035.c(33): warning: illegal bit-field type [35] +msg_035.c(34): warning: illegal bit-field type [35] +msg_035.c(35): warning: illegal bit-field type [35] +msg_035.c(38): warning: illegal bit-field type [35] +msg_035.c(39): warning: illegal bit-field type [35] +msg_035.c(40): warning: illegal bit-field type [35] +msg_035.c(41): void type for void_flag [19] +msg_035.c(41): zero size bit-field [37] +msg_035.c(42): warning: illegal bit-field type [35] +msg_035.c(43): warning: illegal bit-field type [35] +msg_035.c(45): warning: illegal bit-field type [35] +msg_035.c(46): warning: illegal bit-field type [35] +msg_035.c(47): warning: illegal bit-field type [35] +msg_035.c(49): warning: illegal bit-field type [35] +msg_035.c(50): warning: illegal bit-field type [35] +msg_035.c(51): warning: illegal bit-field type [35]