有没有一种方法可以使用 clang 捕获已设置但未使用的变量,类似于 gcc 的 Werror=unused-but-set-parameter
?
我设置了 -Wunused
但 clang 没有捕捉到设置但未使用的参数。
最佳答案
我不确定您尝试的是否比您列出的更多,但这里有更多关于 CLANG 未使用选项的信息,使用它的 GCC 兼容性:
首先,这是文档的建议:
-Wextra -Wunused-but-set-parameter
以下为背景引用资料:
来自 HERE :
如果您使用的是 LLVM-GCC 或 Apple LLVM 编译器构建选项,您可以启用/禁用大量可能的编译器警告。 Clang 前端还支持 GCC 诊断警告(请参阅 http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html)以实现向后兼容性。
按照该引用中的引用链接,列出了 GCC 系列警告中的几个未使用选项:
-墙
这会启用所有关于某些用户认为有问题的构造的警告,并且即使与宏一起使用也很容易避免(或修改以防止警告)。这还会启用 C++ 方言选项和 Objective-C 和 Objective-C++ 方言选项中描述的一些特定于语言的警告。
-Wall turns on the following warning flags:
(there are many more, just listing 'unused')
...
-Wunused-function
-Wunused-label
-Wunused-value
-Wunused-variable
...
最后,就在最后一个 block 的下方:
-Wextra
This enables some extra warning flags that are not enabled by -Wall.
(This option used to be called -W. The older name is still supported, but the newer name is more descriptive.)
(again, there are more, just listing _unused variety)
-Wunused-parameter (only with -Wunused or -Wall)
-Wunused-but-set-parameter (only with -Wunused or -Wall)
关于c++ - 使用 clang 捕获设置但未使用的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24433252/