clang编译器的`-Weverything`选项包括什么,它在哪里记录? [英] What does the clang compiler's `-Weverything` option include and where is it documented?
问题描述
clang(不是gcc)具有一个 -Weverything
选项,该选项出现来包含诸如 -Wpedantic
之类的内容.您可以在此处进行测试:
另请参见:
我真正关心的部分(强调):
由于
-Weverything
启用了每种诊断,因此我们通常不建议使用它.-Wall -Wextra
是更好的选择使用-Weverything
意味着更新编译器更加困难,因为您将面临实验诊断的质量可能会比默认诊断低.如果您确实使用-Weverything
,那么我们建议您解决所有新的编译器诊断,因为它们会被添加到Clang中,或者修复它们找到的所有内容,或者使用其相应的Wno-
选项.
所以,我的最终建议是使用 -Wall -Wextra
发出警告,但不要使用 -Wallything
,就个人而言,请使用 not -Wpedantic
(或 -pedantic
-一样),因为我经常依靠gcc编译器扩展来进行低级嵌入式工作和以硬件为中心的编程,尤其是在微控制器上.>
我还强烈建议使用 -Werror
将所有警告强制变为错误.这对于需要永久运行的安全性至关重要的代码和/或嵌入式固件特别重要,因为它会迫使您修复所有警告以使代码完全编译.因此,我的最终建议是这个,正如我在下面的github存储库中进一步描述的那样:
#Apply'all'和额外"警告,并将它们全部转换为错误#强迫您实际遵守!-Wall -Wextra -Werror
您可以在我的GitHub存储库中阅读有关该主题的更深入的见解和研究:https://github.com/ElectricRCAircraftGuy/eRCaGuy_hello_world#build-notes .
额外说明: -Wpedantic
== -pedantic
:
在gcc中,它们是相同的:
-Wpedantic
-pedantic
发布严格的ISO C和ISO C ++要求的所有警告...
在clang中,它们在测试和文档中似乎也相同.Clang还力求在语法和用法上与gcc兼容:最终用户功能:"..."GCC兼容性".
相关:
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
.
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:
-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".
Related:
这篇关于clang编译器的`-Weverything`选项包括什么,它在哪里记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!