tests/lint: replace 'expect' comments with 'expect+-' comments

The 'expect+-' comments provide more context, which makes it easier to
read the .c files on their own, without having to look up the actual
diagnostics in the .exp files.

Add tests for messages 105 and 106, which were about the obscure feature
of some traditional C compilers that allowed the expression 'x->member'
to access a struct member, even if 'x' had integer type.

The remaining tests will be migrated in a future commit.
This commit is contained in:
rillig 2022-06-15 20:18:31 +00:00
parent 6e7a6fabe9
commit aba9ec7202
74 changed files with 370 additions and 211 deletions

View File

@ -1,5 +1,5 @@
#! /usr/bin/lua
-- $NetBSD: check-expect.lua,v 1.14 2021/12/07 07:09:12 rillig Exp $
-- $NetBSD: check-expect.lua,v 1.15 2022/06/15 20:18:31 rillig Exp $
--[[
@ -60,8 +60,13 @@ local function load_expect_comments_from_c(fname)
add_expectation(tonumber(offset), comment)
end
-- TODO: Remove these comments for all tests, as they often contain
-- only the raw message ID, without the actual message text,
-- which makes them harder to understand without looking up more context.
for comment in line:gmatch("/%* expect: (.-) %*/") do
add_expectation(0, comment)
if not (fname:match("^msg_[0]")) then
add_expectation(0, comment)
end
end
pp_lineno = pp_lineno + 1

View File

@ -1,10 +1,12 @@
/* $NetBSD: msg_000.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_000.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_000.c"
// Test for message: empty declaration [0]
extern int extern_declared;
; /* expect: 0 */
/* expect+1: warning: empty declaration [0] */
;
static int local_defined; /* expect: 226 */
/* expect+1: warning: static variable 'local_defined' unused [226] */
static int local_defined;

View File

@ -1,2 +1,2 @@
msg_000.c(8): warning: empty declaration [0]
msg_000.c(10): warning: static variable 'local_defined' unused [226]
msg_000.c(9): warning: empty declaration [0]
msg_000.c(12): warning: static variable 'local_defined' unused [226]

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_003.c,v 1.4 2021/02/28 12:40:00 rillig Exp $ */
/* $NetBSD: msg_003.c,v 1.5 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_003.c"
// Test for message: '%s' declared in argument declaration list [3]
@ -6,8 +6,11 @@
/*ARGSUSED*/
void
example(declare_struct, declare_union, declare_enum)
struct struct_in_argument *declare_struct; /* expect: 3 */
union union_in_argument *declare_union; /* expect: 3 */
enum enum_in_argument *declare_enum; /* expect: 3 */
/* expect+1: warning: 'incomplete struct struct_in_argument' declared in argument declaration list [3] */
struct struct_in_argument *declare_struct;
/* expect+1: warning: 'incomplete union union_in_argument' declared in argument declaration list [3] */
union union_in_argument *declare_union;
/* expect+1: warning: 'enum enum_in_argument' declared in argument declaration list [3] */
enum enum_in_argument *declare_enum;
{
}

View File

@ -1,3 +1,3 @@
msg_003.c(9): warning: 'incomplete struct struct_in_argument' declared in argument declaration list [3]
msg_003.c(10): warning: 'incomplete union union_in_argument' declared in argument declaration list [3]
msg_003.c(11): warning: 'enum enum_in_argument' declared in argument declaration list [3]
msg_003.c(10): warning: 'incomplete struct struct_in_argument' declared in argument declaration list [3]
msg_003.c(12): warning: 'incomplete union union_in_argument' declared in argument declaration list [3]
msg_003.c(14): warning: 'enum enum_in_argument' declared in argument declaration list [3]

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_004.c,v 1.5 2021/07/04 13:32:35 rillig Exp $ */
/* $NetBSD: msg_004.c,v 1.6 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_004.c"
// Test for message: illegal type combination [4]
@ -10,12 +10,16 @@ int ok_int;
double ok_double;
float _Complex ok_float_complex;
int _Complex illegal_int_complex; /* expect: 4 *//* expect: 308 */
/* expect+2: error: invalid type for _Complex [308] */
/* expect+1: error: illegal type combination [4] */
int _Complex illegal_int_complex;
char enum {
CHAR
}; /* expect: 4 */
};
/* expect-1: error: illegal type combination [4] */
long struct {
int member;
}; /* expect: 4 */
};
/* expect-1: error: illegal type combination [4] */

View File

@ -1,4 +1,4 @@
msg_004.c(13): error: invalid type for _Complex [308]
msg_004.c(13): error: illegal type combination [4]
msg_004.c(17): error: illegal type combination [4]
msg_004.c(21): error: illegal type combination [4]
msg_004.c(15): error: invalid type for _Complex [308]
msg_004.c(15): error: illegal type combination [4]
msg_004.c(19): error: illegal type combination [4]
msg_004.c(24): error: illegal type combination [4]

View File

@ -1,7 +1,9 @@
/* $NetBSD: msg_006.c,v 1.4 2021/04/05 01:35:34 rillig Exp $ */
/* $NetBSD: msg_006.c,v 1.5 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_006.c"
// Test for message: use 'double' instead of 'long float' [6]
long float x; /* expect: 6 *//* expect: 4 */
/* expect+2: warning: use 'double' instead of 'long float' [6] */
/* expect+1: error: illegal type combination [4] */
long float x;
double x;

View File

@ -1,2 +1,2 @@
msg_006.c(6): warning: use 'double' instead of 'long float' [6]
msg_006.c(6): error: illegal type combination [4]
msg_006.c(8): warning: use 'double' instead of 'long float' [6]
msg_006.c(8): error: illegal type combination [4]

View File

@ -1,9 +1,10 @@
/* $NetBSD: msg_008.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_008.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_008.c"
// Test for message: illegal storage class [8]
typedef void
example(void)
{ /* expect: 8 */
/* expect+1: error: illegal storage class [8] */
{
}

View File

@ -1 +1 @@
msg_008.c(8): error: illegal storage class [8]
msg_008.c(9): error: illegal storage class [8]

View File

@ -1,9 +1,13 @@
/* $NetBSD: msg_009.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_009.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_009.c"
// Test for message: only register valid as formal parameter storage class [9]
extern void typedef_example(typedef int param); /* expect: 9 */
extern void auto_example(auto int param); /* expect: 9 */
extern void static_example(static int param); /* expect: 9 */
extern void extern_example(extern int param); /* expect: 9 */
/* expect+1: error: only register valid as formal parameter storage class [9] */
extern void typedef_example(typedef int param);
/* expect+1: error: only register valid as formal parameter storage class [9] */
extern void auto_example(auto int param);
/* expect+1: error: only register valid as formal parameter storage class [9] */
extern void static_example(static int param);
/* expect+1: error: only register valid as formal parameter storage class [9] */
extern void extern_example(extern int param);

View File

@ -1,4 +1,4 @@
msg_009.c(6): error: only register valid as formal parameter storage class [9]
msg_009.c(7): error: only register valid as formal parameter storage class [9]
msg_009.c(8): error: only register valid as formal parameter storage class [9]
msg_009.c(9): error: only register valid as formal parameter storage class [9]
msg_009.c(11): error: only register valid as formal parameter storage class [9]
msg_009.c(13): error: only register valid as formal parameter storage class [9]

View File

@ -1,14 +1,20 @@
/* $NetBSD: msg_019.c,v 1.4 2021/04/05 01:35:34 rillig Exp $ */
/* $NetBSD: msg_019.c,v 1.5 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_019.c"
// Test for message: void type for '%s' [19]
void global_variable; /* expect: 19 */
/* expect+1: error: void type for 'global_variable' [19] */
void global_variable;
static void unit_variable; /* expect: 19 *//* expect: 226 */
/* expect+2: error: void type for 'unit_variable' [19] */
/* expect+1: warning: static variable 'unit_variable' unused [226] */
static void unit_variable;
/* expect+3: warning: argument 'parameter' unused in function 'function' [231] */
/* expect+2: error: void parameter cannot have name: parameter [61] */
void
function(void parameter) /* expect: 61 *//* expect: 231 */
function(void parameter)
{
void local_variable; /* expect: 19 */
/* expect+1: error: void type for 'local_variable' [19] */
void local_variable;
}

View File

@ -1,6 +1,6 @@
msg_019.c(6): error: void type for 'global_variable' [19]
msg_019.c(8): error: void type for 'unit_variable' [19]
msg_019.c(11): error: void parameter cannot have name: parameter [61]
msg_019.c(13): error: void type for 'local_variable' [19]
msg_019.c(11): warning: argument 'parameter' unused in function 'function' [231]
msg_019.c(8): warning: static variable 'unit_variable' unused [226]
msg_019.c(7): error: void type for 'global_variable' [19]
msg_019.c(11): error: void type for 'unit_variable' [19]
msg_019.c(16): error: void parameter cannot have name: parameter [61]
msg_019.c(19): error: void type for 'local_variable' [19]
msg_019.c(16): warning: argument 'parameter' unused in function 'function' [231]
msg_019.c(11): warning: static variable 'unit_variable' unused [226]

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_029.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_029.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_029.c"
// Test for message: previously declared extern, becomes static: %s [29]
@ -6,6 +6,7 @@
extern int function(void);
static int function(void)
{ /* expect: 29 */
/* expect+1: warning: previously declared extern, becomes static: function [29] */
{
return function();
}

View File

@ -1 +1 @@
msg_029.c(9): warning: previously declared extern, becomes static: function [29]
msg_029.c(10): warning: previously declared extern, becomes static: function [29]

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_031.c,v 1.6 2021/07/13 22:01:34 rillig Exp $ */
/* $NetBSD: msg_031.c,v 1.7 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_031.c"
// Test for message: '%s' has incomplete type '%s' [31]
@ -7,7 +7,8 @@ struct complete {
int dummy;
};
struct incomplete; /* expect: 233 */
/* expect+1: warning: struct 'incomplete' never defined [233] */
struct incomplete;
struct complete complete_var;

View File

@ -1,3 +1,3 @@
msg_031.c(20): error: '<unnamed>' has incomplete type 'incomplete struct incomplete' [31]
msg_031.c(10): warning: struct 'incomplete' never defined [233]
msg_031.c(16): error: 'incomplete_var' has incomplete type 'incomplete struct incomplete' [31]
msg_031.c(21): error: '<unnamed>' has incomplete type 'incomplete struct incomplete' [31]
msg_031.c(11): warning: struct 'incomplete' never defined [233]
msg_031.c(17): error: 'incomplete_var' has incomplete type 'incomplete struct incomplete' [31]

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_035.c,v 1.10 2021/12/22 14:25:35 rillig Exp $ */
/* $NetBSD: msg_035.c,v 1.11 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_035.c"
// Test for message: illegal bit-field type '%s' [35]
@ -41,24 +41,48 @@ struct example {
unsigned short unsigned_short_flag: 1;
int int_flag: 1;
unsigned int unsigned_int_flag: 1;
long long_flag: 1; /* expect: 35 */
unsigned long unsigned_long_flag: 1; /* expect: 35 */
long long long_long_flag: 1; /* expect: 35 */
unsigned long long unsigned_long_long_flag: 1; /* expect: 35 */
/* expect+1: warning: illegal bit-field type 'long' [35] */
long long_flag: 1;
/* expect+1: warning: illegal bit-field type 'unsigned long' [35] */
unsigned long unsigned_long_flag: 1;
/* expect+1: warning: illegal bit-field type 'long long' [35] */
long long long_long_flag: 1;
/* expect+1: warning: illegal bit-field type 'unsigned long long' [35] */
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; /* expect: 35 */
double double_flag: 1; /* expect: 35 */
long double long_double_flag: 1; /* expect: 35 */
void void_flag: 1; /* expect: 19 *//* expect: 37 */
example_struct struct_flag: 1; /* expect: 35 */
example_union union_flag: 1; /* expect: 35 */
/* expect+1: warning: illegal bit-field type 'float' [35] */
float float_flag: 1;
/* expect+1: warning: illegal bit-field type 'double' [35] */
double double_flag: 1;
/* expect+1: warning: illegal bit-field type 'long double' [35] */
long double long_double_flag: 1;
/* expect+2: error: void type for 'void_flag' [19] */
/* expect+1: error: zero size bit-field [37] */
void void_flag: 1;
/* expect+1: warning: illegal bit-field type 'struct typedef example_struct' [35] */
example_struct struct_flag: 1;
/* expect+1: warning: illegal bit-field type 'union typedef example_union' [35] */
example_union union_flag: 1;
example_enum enum_flag: 1;
void *pointer_flag: 1; /* expect: 35 */
unsigned int array_flag[4]: 1; /* expect: 35 */
example_function function_flag: 1; /* expect: 35 */
_Complex complex_flag: 1; /* expect: 35 *//* expect: 308 */
float _Complex float_complex_flag: 1; /* expect: 35 */
double _Complex double_complex_flag: 1; /* expect: 35 */
long double _Complex long_double_complex_flag: 1; /* expect: 35 */
/* expect+1: warning: illegal bit-field type 'pointer to void' [35] */
void *pointer_flag: 1;
/* expect+1: warning: illegal bit-field type 'array[4] of unsigned int' [35] */
unsigned int array_flag[4]: 1;
/* expect+1: warning: illegal bit-field type 'function(int, pointer to const char) returning void' [35] */
example_function function_flag: 1;
/* expect+2: error: invalid type for _Complex [308] */
/* expect+1: warning: illegal bit-field type 'double _Complex' [35] */
_Complex complex_flag: 1;
/* expect+1: warning: illegal bit-field type 'float _Complex' [35] */
float _Complex float_complex_flag: 1;
/* expect+1: warning: illegal bit-field type 'double _Complex' [35] */
double _Complex double_complex_flag: 1;
/* expect+1: warning: illegal bit-field type 'long double _Complex' [35] */
long double _Complex long_double_complex_flag: 1;
};

View File

@ -1,19 +1,19 @@
msg_035.c(44): warning: illegal bit-field type 'long' [35]
msg_035.c(45): warning: illegal bit-field type 'unsigned long' [35]
msg_035.c(46): warning: illegal bit-field type 'long long' [35]
msg_035.c(47): warning: illegal bit-field type 'unsigned long long' [35]
msg_035.c(50): warning: illegal bit-field type 'float' [35]
msg_035.c(51): warning: illegal bit-field type 'double' [35]
msg_035.c(52): warning: illegal bit-field type 'long double' [35]
msg_035.c(53): error: void type for 'void_flag' [19]
msg_035.c(53): error: zero size bit-field [37]
msg_035.c(54): warning: illegal bit-field type 'struct typedef example_struct' [35]
msg_035.c(55): warning: illegal bit-field type 'union typedef example_union' [35]
msg_035.c(57): warning: illegal bit-field type 'pointer to void' [35]
msg_035.c(58): warning: illegal bit-field type 'array[4] of unsigned int' [35]
msg_035.c(59): warning: illegal bit-field type 'function(int, pointer to const char) returning void' [35]
msg_035.c(60): error: invalid type for _Complex [308]
msg_035.c(60): warning: illegal bit-field type 'double _Complex' [35]
msg_035.c(61): warning: illegal bit-field type 'float _Complex' [35]
msg_035.c(62): warning: illegal bit-field type 'double _Complex' [35]
msg_035.c(63): warning: illegal bit-field type 'long double _Complex' [35]
msg_035.c(46): warning: illegal bit-field type 'long' [35]
msg_035.c(48): warning: illegal bit-field type 'unsigned long' [35]
msg_035.c(50): warning: illegal bit-field type 'long long' [35]
msg_035.c(52): warning: illegal bit-field type 'unsigned long long' [35]
msg_035.c(58): warning: illegal bit-field type 'float' [35]
msg_035.c(60): warning: illegal bit-field type 'double' [35]
msg_035.c(62): warning: illegal bit-field type 'long double' [35]
msg_035.c(65): error: void type for 'void_flag' [19]
msg_035.c(65): error: zero size bit-field [37]
msg_035.c(67): warning: illegal bit-field type 'struct typedef example_struct' [35]
msg_035.c(69): warning: illegal bit-field type 'union typedef example_union' [35]
msg_035.c(74): warning: illegal bit-field type 'pointer to void' [35]
msg_035.c(76): warning: illegal bit-field type 'array[4] of unsigned int' [35]
msg_035.c(78): warning: illegal bit-field type 'function(int, pointer to const char) returning void' [35]
msg_035.c(81): error: invalid type for _Complex [308]
msg_035.c(81): warning: illegal bit-field type 'double _Complex' [35]
msg_035.c(83): warning: illegal bit-field type 'float _Complex' [35]
msg_035.c(85): warning: illegal bit-field type 'double _Complex' [35]
msg_035.c(87): warning: illegal bit-field type 'long double _Complex' [35]

View File

@ -1,10 +1,12 @@
/* $NetBSD: msg_036.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_036.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_036.c"
// Test for message: illegal bit-field size: %d [36]
struct example {
unsigned int too_large: 100000; /* expect: 36 */
unsigned int negative: -1; /* expect: 36 */
/* expect+1: error: illegal bit-field size: 160 [36] */
unsigned int too_large: 100000;
/* expect+1: error: illegal bit-field size: 255 [36] */
unsigned int negative: -1;
unsigned int ok: 3;
};

View File

@ -1,2 +1,2 @@
msg_036.c(7): error: illegal bit-field size: 160 [36]
msg_036.c(8): error: illegal bit-field size: 255 [36]
msg_036.c(8): error: illegal bit-field size: 160 [36]
msg_036.c(10): error: illegal bit-field size: 255 [36]

View File

@ -1,9 +1,10 @@
/* $NetBSD: msg_037.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_037.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_037.c"
// Test for message: zero size bit-field [37]
struct example {
unsigned int zero: 0; /* expect: 37 */
/* expect+1: error: zero size bit-field [37] */
unsigned int zero: 0;
unsigned int ok: 3;
};

View File

@ -1 +1 @@
msg_037.c(7): error: zero size bit-field [37]
msg_037.c(8): error: zero size bit-field [37]

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_050.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_050.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_050.c"
/* Test for message: a function is declared as an argument: %s [50] */
@ -7,7 +7,9 @@
typedef void (function)();
void example(f) /* expect: 231 */
function f; /* expect: 50 */
/* expect+1: warning: argument 'f' unused in function 'example' [231] */
void example(f)
/* expect+1: warning: a function is declared as an argument: f [50] */
function f;
{
}

View File

@ -1,2 +1,2 @@
msg_050.c(11): warning: a function is declared as an argument: f [50]
msg_050.c(10): warning: argument 'f' unused in function 'example' [231]
msg_050.c(13): warning: a function is declared as an argument: f [50]
msg_050.c(11): warning: argument 'f' unused in function 'example' [231]

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_051.c,v 1.4 2021/04/05 01:35:34 rillig Exp $ */
/* $NetBSD: msg_051.c,v 1.5 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_051.c"
// Test for message: parameter mismatch: %d declared, %d defined [51]
@ -7,7 +7,11 @@ void
example(int, int);
void
example(a, b, c) /* expect: 231 *//* expect: 231 *//* expect: 231 */
/* expect+3: warning: argument 'a' unused in function 'example' [231] */
/* expect+2: warning: argument 'b' unused in function 'example' [231] */
/* expect+1: warning: argument 'c' unused in function 'example' [231] */
example(a, b, c)
int a, b, c;
{ /* expect: 51 */
/* expect+1: error: parameter mismatch: 2 declared, 3 defined [51] */
{
}

View File

@ -1,4 +1,4 @@
msg_051.c(12): error: parameter mismatch: 2 declared, 3 defined [51]
msg_051.c(10): warning: argument 'a' unused in function 'example' [231]
msg_051.c(10): warning: argument 'b' unused in function 'example' [231]
msg_051.c(10): warning: argument 'c' unused in function 'example' [231]
msg_051.c(16): error: parameter mismatch: 2 declared, 3 defined [51]
msg_051.c(13): warning: argument 'a' unused in function 'example' [231]
msg_051.c(13): warning: argument 'b' unused in function 'example' [231]
msg_051.c(13): warning: argument 'c' unused in function 'example' [231]

View File

@ -1,8 +1,9 @@
/* $NetBSD: msg_055.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_055.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_055.c"
// Test for message: integral constant expression expected [55]
enum color {
WHITE = 1.0
}; /* expect: 55 */
};
/* expect-1: error: integral constant expression expected [55] */

View File

@ -1,8 +1,10 @@
/* $NetBSD: msg_056.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_056.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_056.c"
// Test for message: integral constant too large [56]
enum color {
WHITE = 0xFFFFFFFFFFFFFFFFFFFF /* expect: 252 */
}; /* expect: 56 */
/* expect+1: warning: integer constant out of range [252] */
WHITE = 0xFFFFFFFFFFFFFFFFFFFF
};
/* expect-1: warning: integral constant too large [56] */

View File

@ -1,2 +1,2 @@
msg_056.c(7): warning: integer constant out of range [252]
msg_056.c(8): warning: integral constant too large [56]
msg_056.c(8): warning: integer constant out of range [252]
msg_056.c(9): warning: integral constant too large [56]

View File

@ -1,14 +1,26 @@
/* $NetBSD: msg_057.c,v 1.4 2021/04/05 01:35:34 rillig Exp $ */
/* $NetBSD: msg_057.c,v 1.5 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_057.c"
// Test for message: enumeration constant hides parameter: %s [57]
long
rgb(int red, int green, int blue) /* expect: 231 *//* expect: 231 *//* expect: 231 */
/* expect+3: warning: argument 'red' unused in function 'rgb' [231] */
/* expect+2: warning: argument 'green' unused in function 'rgb' [231] */
/* expect+1: warning: argument 'blue' unused in function 'rgb' [231] */
rgb(int red, int green, int blue)
{
enum color {
red, green, blue /* expect: 57 *//* expect: 57 */
}; /* expect: 57 */
/* expect+2: warning: enumeration constant hides parameter: red [57] */
/* expect+1: warning: enumeration constant hides parameter: green [57] */
red, green, blue
};
/* expect-1: warning: enumeration constant hides parameter: blue [57] */
/*
* The warning for 'blue' is at the semicolon since the parser has
* already advanced that far, checking for an optional initializer.
* As of 2022-06-15, lint does not keep track of the location of each
* individual token.
*/
return red + green + blue;
}

View File

@ -1,6 +1,6 @@
msg_057.c(10): warning: enumeration constant hides parameter: red [57]
msg_057.c(10): warning: enumeration constant hides parameter: green [57]
msg_057.c(11): warning: enumeration constant hides parameter: blue [57]
msg_057.c(7): warning: argument 'red' unused in function 'rgb' [231]
msg_057.c(7): warning: argument 'green' unused in function 'rgb' [231]
msg_057.c(7): warning: argument 'blue' unused in function 'rgb' [231]
msg_057.c(15): warning: enumeration constant hides parameter: red [57]
msg_057.c(15): warning: enumeration constant hides parameter: green [57]
msg_057.c(16): warning: enumeration constant hides parameter: blue [57]
msg_057.c(10): warning: argument 'red' unused in function 'rgb' [231]
msg_057.c(10): warning: argument 'green' unused in function 'rgb' [231]
msg_057.c(10): warning: argument 'blue' unused in function 'rgb' [231]

View File

@ -1,8 +1,14 @@
/* $NetBSD: msg_060.c,v 1.4 2021/04/05 01:35:34 rillig Exp $ */
/* $NetBSD: msg_060.c,v 1.5 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_060.c"
// Test for message: void must be sole parameter [60]
void example_1(void);
void example_2(int, void); /* expect: 60 */
void example_3(void, void, void); /* expect: 60 *//* expect: 60 *//* expect: 60 */
/* expect+1: error: void must be sole parameter [60] */
void example_2(int, void);
/* expect+3: error: void must be sole parameter [60] */
/* expect+2: error: void must be sole parameter [60] */
/* expect+1: error: void must be sole parameter [60] */
void example_3(void, void, void);

View File

@ -1,4 +1,4 @@
msg_060.c(7): error: void must be sole parameter [60]
msg_060.c(8): error: void must be sole parameter [60]
msg_060.c(8): error: void must be sole parameter [60]
msg_060.c(8): error: void must be sole parameter [60]
msg_060.c(9): error: void must be sole parameter [60]
msg_060.c(14): error: void must be sole parameter [60]
msg_060.c(14): error: void must be sole parameter [60]
msg_060.c(14): error: void must be sole parameter [60]

View File

@ -1,6 +1,7 @@
/* $NetBSD: msg_061.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_061.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_061.c"
// Test for message: void parameter cannot have name: %s [61]
void example(void arg); /* expect: 61 */
/* expect+1: error: void parameter cannot have name: arg [61] */
void example(void arg);

View File

@ -1 +1 @@
msg_061.c(6): error: void parameter cannot have name: arg [61]
msg_061.c(7): error: void parameter cannot have name: arg [61]

View File

@ -1,8 +1,9 @@
/* $NetBSD: msg_068.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_068.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_068.c"
// Test for message: typedef already qualified with '%s' [68]
typedef const char const_char;
const const_char twice_const; /* expect: 68 */
/* expect+1: warning: typedef already qualified with 'const' [68] */
const const_char twice_const;

View File

@ -1 +1 @@
msg_068.c(8): warning: typedef already qualified with 'const' [68]
msg_068.c(9): warning: typedef already qualified with 'const' [68]

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_071.c,v 1.4 2021/04/05 01:35:34 rillig Exp $ */
/* $NetBSD: msg_071.c,v 1.5 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_071.c"
// Test for message: too many characters in character constant [71]
@ -8,4 +8,6 @@
* sequence of characters that can constitute the escape sequence.
*/
char valid_multi_digit_hex = '\x0000000000000000000000a';
char invalid_multi_digit_hex = '\x000g000000000000000000a'; /* expect: 71 *//* expect: 178 */
/* expect+2: error: too many characters in character constant [71] */
/* expect+1: warning: initializer does not fit [178] */
char invalid_multi_digit_hex = '\x000g000000000000000000a';

View File

@ -1,2 +1,2 @@
msg_071.c(11): error: too many characters in character constant [71]
msg_071.c(11): warning: initializer does not fit [178]
msg_071.c(13): error: too many characters in character constant [71]
msg_071.c(13): warning: initializer does not fit [178]

View File

@ -1,7 +1,8 @@
/* $NetBSD: msg_073.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_073.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_073.c"
// Test for message: empty character constant [73]
char empty = ''; /* expect: 73 */
/* expect+1: error: empty character constant [73] */
char empty = '';
char letter = 'x';

View File

@ -1 +1 @@
msg_073.c(6): error: empty character constant [73]
msg_073.c(7): error: empty character constant [73]

View File

@ -1,9 +1,14 @@
/* $NetBSD: msg_074.c,v 1.4 2021/04/05 01:35:34 rillig Exp $ */
/* $NetBSD: msg_074.c,v 1.5 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_074.c"
// Test for message: no hex digits follow \x [74]
char invalid_hex = '\x'; /* expect: 74 */
char invalid_hex_letter = '\xg'; /* expect: 74 *//* expect: 294 */
/* expect+1: error: no hex digits follow \x [74] */
char invalid_hex = '\x';
/* expect+2: error: no hex digits follow \x [74] */
/* expect+1: warning: multi-character character constant [294] */
char invalid_hex_letter = '\xg';
char valid_hex = '\xff';
char valid_single_digit_hex = '\xa';

View File

@ -1,3 +1,3 @@
msg_074.c(6): error: no hex digits follow \x [74]
msg_074.c(7): error: no hex digits follow \x [74]
msg_074.c(7): warning: multi-character character constant [294]
msg_074.c(11): error: no hex digits follow \x [74]
msg_074.c(11): warning: multi-character character constant [294]

View File

@ -1,6 +1,7 @@
/* $NetBSD: msg_075.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_075.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_075.c"
// Test for message: overflow in hex escape [75]
char str[] = "\x12345678123456781234567812345678"; /* expect: 75 */
/* expect+1: warning: overflow in hex escape [75] */
char str[] = "\x12345678123456781234567812345678";

View File

@ -1 +1 @@
msg_075.c(6): warning: overflow in hex escape [75]
msg_075.c(7): warning: overflow in hex escape [75]

View File

@ -1,6 +1,7 @@
/* $NetBSD: msg_076.c,v 1.3 2021/06/29 07:17:43 rillig Exp $ */
/* $NetBSD: msg_076.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_076.c"
// Test for message: character escape does not fit in character [76]
char ch = '\777'; /* expect: [76] */
/* expect+1: warning: character escape does not fit in character [76] */
char ch = '\777';

View File

@ -1 +1 @@
msg_076.c(6): warning: character escape does not fit in character [76]
msg_076.c(7): warning: character escape does not fit in character [76]

View File

@ -1,11 +1,12 @@
/* $NetBSD: msg_077.c,v 1.4 2021/06/29 07:23:21 rillig Exp $ */
/* $NetBSD: msg_077.c,v 1.5 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_077.c"
/* Test for message: bad octal digit %c [77] */
/* lint1-flags: -tw */
char single_digit = '\8'; /* expect: bad octal digit 8 [77] */
/* expect+1: warning: bad octal digit 8 [77] */
char single_digit = '\8';
/*
* Before lex.c 1.47 from 2021-06-29, lint intended to detect a "bad octal

View File

@ -1,2 +1,2 @@
msg_077.c(8): warning: bad octal digit 8 [77]
msg_077.c(26): warning: multi-character character constant [294]
msg_077.c(9): warning: bad octal digit 8 [77]
msg_077.c(27): warning: multi-character character constant [294]

View File

@ -1,8 +1,9 @@
/* $NetBSD: msg_081.c,v 1.4 2022/04/16 13:25:27 rillig Exp $ */
/* $NetBSD: msg_081.c,v 1.5 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_081.c"
/* Test for message: \a undefined in traditional C [81] */
/* lint1-flags: -tw */
char str[] = "The bell\a rings"; /* expect: 81 */
/* expect+1: warning: \a undefined in traditional C [81] */
char str[] = "The bell\a rings";

View File

@ -1 +1 @@
msg_081.c(8): warning: \a undefined in traditional C [81]
msg_081.c(9): warning: \a undefined in traditional C [81]

View File

@ -1,8 +1,9 @@
/* $NetBSD: msg_082.c,v 1.4 2021/06/29 07:17:43 rillig Exp $ */
/* $NetBSD: msg_082.c,v 1.5 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_082.c"
/* Test for message: \x undefined in traditional C [82] */
/* lint1-flags: -Stw */
char str[] = "A he\x78 escape"; /* expect: [82] */
/* expect+1: warning: \x undefined in traditional C [82] */
char str[] = "A he\x78 escape";

View File

@ -1 +1 @@
msg_082.c(8): warning: \x undefined in traditional C [82]
msg_082.c(9): warning: \x undefined in traditional C [82]

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_083.c,v 1.4 2021/07/10 18:34:03 rillig Exp $ */
/* $NetBSD: msg_083.c,v 1.5 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_083.c"
// Test for message: storage class after type is obsolescent [83]
@ -6,7 +6,8 @@
void
example(void)
{
int register x; /* expect: 83 */
/* expect+1: warning: storage class after type is obsolescent [83] */
int register x;
}
struct {

View File

@ -1,2 +1,2 @@
msg_083.c(9): warning: storage class after type is obsolescent [83]
msg_083.c(14): warning: storage class after type is obsolescent [83]
msg_083.c(10): warning: storage class after type is obsolescent [83]
msg_083.c(15): warning: storage class after type is obsolescent [83]

View File

@ -1,11 +1,15 @@
/* $NetBSD: msg_085.c,v 1.3 2021/01/31 09:21:24 rillig Exp $ */
/* $NetBSD: msg_085.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_085.c"
// Test for message: dubious tag declaration: %s %s [85]
void declare_struct(struct in_argument *); /* expect: 85 */
void declare_union(union in_argument *); /* expect: 85 */
void declare_enum(enum in_argument *); /* expect: 85 */
/* expect+1: warning: dubious tag declaration: struct in_argument [85] */
void declare_struct(struct in_argument *);
/* expect+1: warning: dubious tag declaration: union in_argument [85] */
void declare_union(union in_argument *);
/* expect+1: warning: dubious tag declaration: enum in_argument [85] */
void declare_enum(enum in_argument *);
struct ok; /* expect: 233 */
/* expect+1: warning: struct 'ok' never defined [233] */
struct ok;
extern int ok(struct ok *);

View File

@ -1,4 +1,4 @@
msg_085.c(6): warning: dubious tag declaration: struct in_argument [85]
msg_085.c(7): warning: dubious tag declaration: union in_argument [85]
msg_085.c(8): warning: dubious tag declaration: enum in_argument [85]
msg_085.c(10): warning: struct 'ok' never defined [233]
msg_085.c(7): warning: dubious tag declaration: struct in_argument [85]
msg_085.c(9): warning: dubious tag declaration: union in_argument [85]
msg_085.c(11): warning: dubious tag declaration: enum in_argument [85]
msg_085.c(14): warning: struct 'ok' never defined [233]

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_086.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_086.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_086.c"
// Test for message: automatic hides external declaration: %s [86]
@ -10,7 +10,8 @@ extern int identifier;
int
local_auto(void)
{
int identifier = 3; /* expect: 86 */
/* expect+1: warning: automatic hides external declaration: identifier [86] */
int identifier = 3;
return identifier;
}

View File

@ -1 +1 @@
msg_086.c(13): warning: automatic hides external declaration: identifier [86]
msg_086.c(14): warning: automatic hides external declaration: identifier [86]

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_087.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_087.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_087.c"
// Test for message: static hides external declaration: %s [87]
@ -10,6 +10,7 @@ extern int counter;
int
count(void)
{
static int counter; /* expect: 87 */
/* expect+1: warning: static hides external declaration: counter [87] */
static int counter;
return counter++;
}

View File

@ -1 +1 @@
msg_087.c(13): warning: static hides external declaration: counter [87]
msg_087.c(14): warning: static hides external declaration: counter [87]

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_088.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_088.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_088.c"
// Test for message: typedef hides external declaration: %s [88]
@ -10,5 +10,6 @@ extern int identifier;
void
func(void)
{
typedef double identifier; /* expect: 88 */
/* expect+1: warning: typedef hides external declaration: identifier [88] */
typedef double identifier;
}

View File

@ -1 +1 @@
msg_088.c(13): warning: typedef hides external declaration: identifier [88]
msg_088.c(14): warning: typedef hides external declaration: identifier [88]

View File

@ -1,8 +1,10 @@
/* $NetBSD: msg_089.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
/* $NetBSD: msg_089.c,v 1.4 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_089.c"
// Test for message: typedef redeclared: %s [89]
typedef int number;
typedef int number; /* expect: 89 */
typedef double number; /* expect: 89 */
/* expect+1: error: typedef redeclared: number [89] */
typedef int number;
/* expect+1: error: typedef redeclared: number [89] */
typedef double number;

View File

@ -1,2 +1,2 @@
msg_089.c(7): error: typedef redeclared: number [89]
msg_089.c(8): error: typedef redeclared: number [89]
msg_089.c(10): error: typedef redeclared: number [89]

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_100.c,v 1.4 2022/04/16 13:25:27 rillig Exp $ */
/* $NetBSD: msg_100.c,v 1.5 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_100.c"
/* Test for message: unary + is illegal in traditional C [100] */
@ -6,7 +6,9 @@
/* lint1-flags: -tw */
int
unary_plus(int x)
{ /* expect: 270 */
return +x; /* expect: 100 */
unary_plus(x)
int x;
{
/* expect+1: warning: unary + is illegal in traditional C [100] */
return +x;
}

View File

@ -1,2 +1 @@
msg_100.c(10): warning: function prototypes are illegal in traditional C [270]
msg_100.c(11): warning: unary + is illegal in traditional C [100]
msg_100.c(13): warning: unary + is illegal in traditional C [100]

View File

@ -1,7 +1,46 @@
/* $NetBSD: msg_105.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
/* $NetBSD: msg_105.c,v 1.3 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_105.c"
// Test for message: non-unique member requires struct/union %s [105]
/* Test for message: non-unique member requires struct/union %s [105] */
TODO: "Add example code that triggers the above message." /* expect: 249 */
TODO: "Add example code that almost triggers the above message."
/* lint1-flags: -tw */
/*
* In traditional C, the expression 'x->y' did not only allow struct or union
* pointers for 'x', but in fact any scalar expression, which would then be
* dereferenced as if it were a struct or union.
*
* This led to ambiguities if several structs had a member of the same name
* but with different offsets. In such a case, that member name could only
* be used with one of its actual struct types.
*/
struct one {
int member;
};
struct two {
int before_member; /* make the offset of 'member' different */
int member;
};
struct three {
int x;
int y;
};
int
example(x)
int *x;
{
/* expect+1: error: non-unique member requires struct/union pointer [105] */
return x->member;
}
int
member_of_wrong_struct(t)
struct three *t;
{
/* expect+1: error: illegal member use: member [102] */
return t->member;
}

View File

@ -1 +1,2 @@
msg_105.c(6): error: syntax error ':' [249]
msg_105.c(37): error: non-unique member requires struct/union pointer [105]
msg_105.c(45): error: illegal member use: member [102]

View File

@ -1,7 +1,17 @@
/* $NetBSD: msg_106.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
/* $NetBSD: msg_106.c,v 1.3 2022/06/15 20:18:31 rillig Exp $ */
# 3 "msg_106.c"
// Test for message: left operand of '->' must be pointer [106]
// This message is not used.
TODO: "Add example code that triggers the above message." /* expect: 249 */
TODO: "Add example code that almost triggers the above message."
struct s {
int member;
};
void example(struct s s)
{
s.member++;
/* expect+1: error: left operand of '->' must be pointer to struct or union, not 'struct s' [104] */
return s->member;
}

View File

@ -1 +1 @@
msg_106.c(6): error: syntax error ':' [249]
msg_106.c(16): error: left operand of '->' must be pointer to struct or union, not 'struct s' [104]