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

nev*_*nom 5 c c++ clang

有没有办法可以使用类似于 gcc 的 clang 来捕获已设置但未使用的变量Werror=unused-but-set-parameter?我设置了-Wunused但 clang 没有捕获设置但未使用的参数。

ryy*_*ker 1

我不确定您是否尝试了比您列出的更多的内容,但这里有关于 CLANG未使用选项的更多信息,使用其 GCC 兼容性:

首先,这是文档的建议:

-Wextra  -Wunused-but-set-parameter  
Run Code Online (Sandbox Code Playgroud)

以下是背景参考信息:

这里

如果您使用 LLVM-GCC 或 Apple LLVM 编译器构建选项,则可以启用/禁用大量可能的编译器警告。Clang 前端还支持 GCC 诊断警告(请参阅http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html)以实现向后兼容性。

该引用中引用的链接列出了GCC 警告系列中的 几个未使用的选项:

-Wall
这会启用有关某些用户认为有问题的结构的所有警告,并且很容易避免(或修改以防止警告),即使与宏结合使用也是如此。这还启用了 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  
              ... 
Run Code Online (Sandbox Code Playgroud)

最后,就在最后一个块的下方:

-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)  
Run Code Online (Sandbox Code Playgroud)