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

Caught set but unused parameters with clang

本文关键字:未使用 参数 设置 clang      更新时间:2023-10-16

是否有一种方法可以使用clang捕获集但未使用的变量,类似于gcc的Werror=unused-but-set-parameter ?我设置了-Wunused,但是clang没有捕捉到未使用的参数

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

第一个 ,这是文档的建议:

-Wextra  -Wunused-but-set-parameter  

背景参考信息如下:

从<<p> strong> :

如果您正在使用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  
              ... 

最后,在最后一个代码块下面:

-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)  

clang-tidy生成了一个等效的警告,从clang-analyzer集成:

note: Value stored to 'tmp' is never read
warning: Value stored to 'tmp' is never read [clang-analyzer-deadcode.DeadStores]

看起来LLVM选择将一些GCC警告作为单独的工具来实现。

在这个网站中,如果你搜索" unused ",你可以找到一些你可以使用的标志。我认为这是你的标志:

clang -Wunused-variable test.c