c++ - 使用 clang 捕获设置但未使用的参数

标签 c++ c clang

有没有一种方法可以使用 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/

相关文章:

c++ - 使用 FFT (FFTW) 计算两个函数的卷积

python - 在 C 中嵌入 Python : unable to read python return integer value

c - c计数器的实现

c++ - 如何为使用Clang LLVM编译的C++代码生成图形代码配置文件报告?

GCC 编译器选项 -wno-four-char-constants 和 -wno-multichar

c - 未知类型名称 'siginfo_t' 与使用 _POSIX_C_SOURCE 2 的 Clang,为什么?

c++ - 将 boost 属性树(ptree)序列化为 vector 的最快方法是什么

c++ - 不能很好地使用send()和recv(),短字符串的第一个字节丢失了。c++

c++ - 通过值而不是键访问 QMap 元素

c - 使用宏进行类型检查