用clang捕获设置但未使用的参数
Caught set but unused parameters with clang
是否有一种方法可以使用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
相关文章:
- 仅当一个参数中未使用 std::function 时,模板函数替换才有效
- isPalindrome不显示输出,isPalindrome函数未使用字符串输入作为字符串参数进行测试
- "(void) cast"与功能有什么区别 "__attributes__"来沉默未使用的参数警告?
- 具有未使用的模板参数的函数模板
- 参数设置但未使用
- 未使用模板类型定义的同时参数包扩展错误
- 警告:用两个参数构造函数返回对象时,表达结果未使用
- 尝试使用参数包绑定 std::function 时获取未声明的参数
- clang:警告:编译期间未使用的参数:"-stdlib=libc++"
- C++:错误:成员访问不完整的类型,未使用的参数[-Werror,-Wunused-parameter]
- 运算符++:引用与值返回和未使用的参数
- 在C++中,是否可以使用定义中未使用的模板参数声明模板结构?
- 如何强制MSVC链接一个未使用的静态库(相当于GC——整个归档参数)
- 在 excel 中使用 C++ dll 时未考虑参数
- 调试代码并C++未使用的参数警告
- C++:未使用参数优化的力度
- 用于未使用参数参考的单线解决方案
- 函数调用中未使用的参数的模板参数推导
- 可移植的未使用参数宏用于C和c++的函数签名
- 在gcc和Clang中没有关于模板函数中未使用参数的警告