问题
clang, but NOT gcc, has a -Weverything
option which appears to include things such as -Wpedantic
. You can test it here: https://godbolt.org/z/qcYKd1. See the top-right of the window for where I have typed in -Weverything
as an explicit compiler option.
Notice the -Wvla-extension
warning we get since we are relying on a C99 extension in C++ in this case, and we have -Weverything
set. We get the same warning if we just use -Wpedantic
, as shown here: https://godbolt.org/z/M9ahE4, indicating that -Weverything
does in fact include -Wpedantic
.
We get no warning if we have neither of those flags set: https://godbolt.org/z/j8sfsY.
Despite -Weverything
existing and working in clang, however, I can find no documentation whatsoever on its existence, neither in the clang man pages nor in the online manual here: https://clang.llvm.org/docs/DiagnosticsReference.html. Maybe I'm looking in the wrong place? I'm not super familiar with clang's manual.
So, what does -Weverything
include and where is it documented?
It seems logical to do something like -Wall -Werror -Weverything
, but I don't know how that differs from just -Wall -Werror
.
回答1:
Dope! I just found it.
The bottom of the main clang documentation index page: https://clang.llvm.org/docs/index.html, under the "Indices and tables" section at the very bottom, has a "Search Page" link. Using that link, here is my search for "-Weverything": https://clang.llvm.org/docs/search.html?q=-Weverything, which brings me to the official documentation here!: https://clang.llvm.org/docs/UsersManual.html?highlight=weverything#cmdoption-weverything. Done! There it is!
See also: https://clang.llvm.org/docs/UsersManual.html?highlight=weverything#diagnostics-enable-everything
And the parts I really care about (emphasis added):
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 correspondingWno-
option.
So, my final recommendation is to use -Wall -Wextra
for warnings, but NOT -Weverything
, and personally, not -Wpedantic
(or -pedantic
--same thing) either since I frequently rely on gcc compiler extensions for low-level embedded work and hardware-centric programming, especially on microcontrollers.
I also strongly recommend forcing all warnings into errors with -Werror
. This is particularly important for safety-critical code and/or embedded firmware that needs to run forever, because it forces you to fix all warnings to get the code to fully compile. So, my final recommendation is this, as I describe further in my github repo below:
# Apply "all" and "extra" warnings, and convert them all to errors
# to force you to actually abide by them!
-Wall -Wextra -Werror
You can read my more-thorough opinion and research on this topic in my GitHub repo here: https://github.com/ElectricRCAircraftGuy/eRCaGuy_hello_world#build-notes.
Extra notes: -Wpedantic
== -pedantic
:
In gcc, they are the same:
- Both are listed together.
-Wpedantic
-pedantic
Issue all the warnings demanded by strict ISO C and ISO C++...
In clang, they appear to be the same too, in testing and documentation. Clang also strives to be gcc-compatible in their syntax and usage: "End-User Features:"..."GCC compatibility".
- -pedantic
- -Wpedantic
Related:
- Why should I always enable compiler warnings?
来源:https://stackoverflow.com/questions/64147706/what-does-the-clang-compilers-weverything-option-include-and-where-is-it-doc