@applejack @LukeAlmighty @matrix
There is no such thing as consistent behavior for linters and it’s rather well known that linux kernel has it’s own, but well, the horribly old one called splint still does by default:
$ cat hello.c
#include <stdio.h> // puts
int
main(int argc, char *argv[]) {
(void)argc;
if ((argv[1] = "--help")) {
(void)puts(".");
}
(void)puts(argv[1]);
return 0;
}
$ make hello CFLAGS="-Wall -Wextra"
cc -Wall -Wextra hello.c -o hello
hello.c: In function ‘main’:
hello.c:6:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
6 | if (argv[1] = "--help") {
| ^~~~
$ ./hello
.
--help
$ splint hello.c
Splint 3.1.2 --- 03 Feb 2021
hello.c: (in function main)
hello.c:5:2: Statement has no effect: (void)argc
Statement has no visible effect --- no values are modified. (Use -noeffect to
inhibit warning)
hello.c:6:7: Observer storage assigned to unqualified reference:
argv[1] = "--help"
Observer storage is transferred to a non-observer reference. (Use
-observertrans to inhibit warning)
hello.c:6:17: Storage becomes observer
Finished checking --- 2 code warnings
$
@applejack @LukeAlmighty @matrix That’s probably because assigning into a while is rather common, for example while((c = getopt(argc, argv, ":d:u")) != -1) is idiomatic in C but I wouldn’t be surprised that the linux kernel linter warns about it.