首页 > 解决方案 > What does the clang compiler's `-Weverything` option include and where is it documented?

问题描述

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.

标签: c++buildclangcompiler-flags

解决方案


涂料!我刚找到它。

主要 clang 文档索引页面的底部:https://clang.llvm.org/docs/index.html,在最底部的“索引和表格”部分下,有一个“搜索页面”链接。使用该链接,这是我对“-Weverything”的搜索:https ://clang.llvm.org/docs/search.html?q=-Weverything ,这将我带到这里的官方文档!:https://clang .llvm.org/docs/UsersManual.html?highlight=weverything#cmdoption-weverything。完毕!就在那里!

在此处输入图像描述

另请参阅:https ://clang.llvm.org/docs/UsersManual.html?highlight=weverything#diagnostics-enable-everything

在此处输入图像描述

而我真正关心的部分(重点补充):

由于-Weverything启用每个诊断,我们通常不建议使用它。 -Wall -Wextra是大多数项目的更好选择。使用-Weverything意味着更新编译器更加困难,因为您会接触到质量可能低于默认诊断的实验性诊断。如果您确实使用-Weverything了,那么我们建议您在添加到 Clang 时解决所有新的编译器诊断问题,方法是修复他们找到的所有内容,或者使用相应的Wno-选项显式禁用该诊断。

因此,我的最终建议是-Wall -Wextra用于警告,但 NOT -Weverything,个人而言,也不 -Wpedantic是(或-pedantic--same 东西),因为我经常依赖 gcc 编译器扩展来进行低级嵌入式工作和以硬件为中心的编程,尤其是在微控制器上。

我还强烈建议使用-Werror. 这对于需要永久运行的安全关键代码和/或嵌入式固件尤其重要,因为它会强制您修复所有警告以使代码完全编译。所以,我的最终建议是这样的,正如我在下面的 github 存储库中进一步描述的那样:

# Apply "all" and "extra" warnings, and convert them all to errors
# to force you to actually abide by them!
-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 兼容性”。

有关的:

  1. 为什么我应该总是启用编译器警告?

推荐阅读