Before clang 16.0 I was able to compile all my projects using -Weveything without problems, fixing my code and paying attention to the (useful) warnings that this option gave. However, it seems that the -Wunsafe-buffer-usage was added in version 16 (my system updated to it recently) and then compiling any project is impossible without getting a huge list of useless warnings about any pointer being used, see minimal example below:
$ cat main.c #include <stdio.h> int main(int argc, char **argv) { if (argc != 2) { return 0; } printf("argv[1] = %s\n", argv[1]); } $ clang -Weverything main.c main.c:3:27: warning: 'argv' is an unsafe pointer used for buffer access [-Wunsafe-buffer-usage] int main(int argc, char **argv) { ~~~~~~~^~~~ main.c:7:30: note: used in buffer access here printf("argv[1] = %s\n", argv[1]); ^~~~ 1 warning generated. One can't possibly reason about his code using this warning.
The clang documentation has the following to say:
Since -Weverything enables every diagnostic, we generally don’t recommend using it. -Wall -Wextra are a better choice for most projects. Using -Weverything means that updating your compiler is more difficult because you’re exposed to experimental diagnostics which might be of lower quality than the default ones. If you do use -Weverything then we advise that you address all new compiler diagnostics as they get added to Clang, either by fixing everything they find or explicitly disabling that diagnostic with its corresponding Wno- option.
In this case, how would I "fix everything they find"?
Setting -Wno-unsafe-buffer-usage works, but it is an ugly solution. It adds clutter to a Makefile and feels like cheating.
-Weverythingmay not be a battle you want to start. You may be able to make-Weverythinghappy in this case, but there will be many more warnings you'll need to satisfy, many of which may require making your code worse to "fix". For example, satisfying-Wdeclaration-after-statementwould require declaring all local variables at the top of functions instead of as needed.-Weverything, I also counter some options with-Wno-xyzvariants. One script I use has:-Weverything -Wno-padded -Wno-vla -Wno-reserved-id-macro -Wno-documentation-unknown-command -Wno-poison-system-directories -Wno-format-nonliteral. I build format strings in a number of the programs, hence-Wno-format-nonliteral. I use VLAs in matrix manipulation code (and carefully in other places too), so I need-Wno-vla. I use feature test macros (for POSIX, and also systems like Solaris) to determine how to compile code, so-Wno-reserved-id-macrowas necessary. […continued…]-Weverything. My Mac has Apple's Clang 14.0; the-Wunsafe-buffer-usageoption isn't valid.-Wno-unsafe-buffer-usagefeels like cheating, doesn't-Weverythingfeel like an unreasonable handicap?-Wall -Wextrais expected to be a useful set of warnings, as your quoted extract states.