tests/lint: add tests for a few more messages
This commit is contained in:
parent
b803b07d9e
commit
e80f308ca7
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: msg_031.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
|
||||
/* $NetBSD: msg_031.c,v 1.4 2021/03/16 23:39:41 rillig Exp $ */
|
||||
# 3 "msg_031.c"
|
||||
|
||||
// Test for message: incomplete structure or union %s: %s [31]
|
||||
|
@ -13,3 +13,6 @@ struct incomplete; /* expect: 233 */
|
|||
struct complete complete_var;
|
||||
|
||||
struct incomplete incomplete_var; /* expect: 31 */
|
||||
|
||||
/* XXX: the 'incomplete: <unnamed>' in the diagnostic looks strange */
|
||||
void function(struct incomplete); /* expect: incomplete: <unnamed> [31] */
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
msg_031.c(18): incomplete structure or union incomplete: <unnamed> [31]
|
||||
msg_031.c(10): warning: struct incomplete never defined [233]
|
||||
msg_031.c(15): incomplete structure or union incomplete: incomplete_var [31]
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
/* $NetBSD: msg_151.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
|
||||
/* $NetBSD: msg_151.c,v 1.3 2021/03/16 23:39:41 rillig Exp $ */
|
||||
# 3 "msg_151.c"
|
||||
|
||||
// Test for message: void expressions may not be arguments, arg #%d [151]
|
||||
|
||||
TODO: "Add example code that triggers the above message." /* expect: 249 */
|
||||
TODO: "Add example code that almost triggers the above message."
|
||||
void sink_int(int);
|
||||
|
||||
void
|
||||
example(int i)
|
||||
{
|
||||
sink_int((void)i); /* expect: 151 */
|
||||
sink_int(i);
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
msg_151.c(6): syntax error ':' [249]
|
||||
msg_151.c(11): void expressions may not be arguments, arg #1 [151]
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
/* $NetBSD: msg_152.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
|
||||
/* $NetBSD: msg_152.c,v 1.3 2021/03/16 23:39:41 rillig Exp $ */
|
||||
# 3 "msg_152.c"
|
||||
|
||||
// Test for message: argument cannot have unknown size, arg #%d [152]
|
||||
|
||||
TODO: "Add example code that triggers the above message." /* expect: 249 */
|
||||
TODO: "Add example code that almost triggers the above message."
|
||||
struct incomplete; /* expect: 233 */
|
||||
|
||||
void callee(struct incomplete); /* expect: 31 */
|
||||
|
||||
void
|
||||
caller(void)
|
||||
{
|
||||
struct incomplete local_var; /* expect: 31 */
|
||||
callee(local_var); /* expect: 152 */
|
||||
}
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
msg_152.c(6): syntax error ':' [249]
|
||||
msg_152.c(8): incomplete structure or union incomplete: <unnamed> [31]
|
||||
msg_152.c(13): incomplete structure or union incomplete: local_var [31]
|
||||
msg_152.c(14): argument cannot have unknown size, arg #1 [152]
|
||||
msg_152.c(6): warning: struct incomplete never defined [233]
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
/* $NetBSD: msg_154.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
|
||||
/* $NetBSD: msg_154.c,v 1.3 2021/03/16 23:39:41 rillig Exp $ */
|
||||
# 3 "msg_154.c"
|
||||
|
||||
// Test for message: illegal combination of %s (%s) and %s (%s), arg #%d [154]
|
||||
|
||||
TODO: "Add example code that triggers the above message." /* expect: 249 */
|
||||
TODO: "Add example code that almost triggers the above message."
|
||||
void sink_int(int);
|
||||
|
||||
void
|
||||
example(int *ptr)
|
||||
{
|
||||
sink_int(ptr); /* expect: 154 */
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
msg_154.c(6): syntax error ':' [249]
|
||||
msg_154.c(11): warning: illegal combination of integer (int) and pointer (pointer to int), arg #1 [154]
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
/* $NetBSD: msg_157.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
|
||||
/* $NetBSD: msg_157.c,v 1.3 2021/03/16 23:39:41 rillig Exp $ */
|
||||
# 3 "msg_157.c"
|
||||
|
||||
// Test for message: ANSI C treats constant as unsigned [157]
|
||||
|
||||
TODO: "Add example code that triggers the above message." /* expect: 249 */
|
||||
TODO: "Add example code that almost triggers the above message."
|
||||
/*
|
||||
* A rather strange definition for an ARGB color.
|
||||
* Luckily, 'double' has more than 32 significant binary digits.
|
||||
*/
|
||||
double white = 0xFFFFFFFF; /* expect: 157 */
|
||||
|
|
|
@ -1 +1 @@
|
|||
msg_157.c(6): syntax error ':' [249]
|
||||
msg_157.c(10): warning: ANSI C treats constant as unsigned [157]
|
||||
|
|
|
@ -1,7 +1,43 @@
|
|||
/* $NetBSD: msg_158.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
|
||||
/* $NetBSD: msg_158.c,v 1.3 2021/03/16 23:39:41 rillig Exp $ */
|
||||
# 3 "msg_158.c"
|
||||
|
||||
// Test for message: %s may be used before set [158]
|
||||
|
||||
TODO: "Add example code that triggers the above message." /* expect: 249 */
|
||||
TODO: "Add example code that almost triggers the above message."
|
||||
void sink_int(int);
|
||||
|
||||
void
|
||||
example(int arg)
|
||||
{
|
||||
int twice_arg;
|
||||
|
||||
sink_int(twice_arg); /* expect: 158 */
|
||||
twice_arg = 2 * arg;
|
||||
sink_int(twice_arg);
|
||||
}
|
||||
|
||||
void
|
||||
conditionally_used(int arg)
|
||||
{
|
||||
int twice_arg;
|
||||
|
||||
if (arg > 0)
|
||||
twice_arg = 2 * arg;
|
||||
if (arg > 0)
|
||||
sink_int(twice_arg);
|
||||
}
|
||||
|
||||
void
|
||||
conditionally_unused(int arg)
|
||||
{
|
||||
int twice_arg;
|
||||
|
||||
if (arg > 0)
|
||||
twice_arg = 2 * arg;
|
||||
|
||||
/*
|
||||
* This situation is not detected by lint as it does not track the
|
||||
* possible code paths for all conditions.
|
||||
*/
|
||||
if (arg < 0)
|
||||
sink_int(twice_arg);
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
msg_158.c(6): syntax error ':' [249]
|
||||
msg_158.c(13): warning: twice_arg may be used before set [158]
|
||||
|
|
Loading…
Reference in New Issue