GCC -Wunused功能不起作用(但其他警告正在起作用) [英] GCC -Wunused-function not working (but other warnings are working)
问题描述
我试图通过使用GCC的 -Wunused-function
标志在代码库中找到未使用的函数。
I'm trying to find unused functions in my codebase by using GCC's -Wunused-function
flag.
如我所料,用 gcc -Wall -Wunused-function main.cpp
编译以下代码会显示未使用变量
警告:
As I would expect, compiling the below code with gcc -Wall -Wunused-function main.cpp
prints an unused variable
warning:
warning: unused variable ‘x’ [-Wunused-variable]
但是,编译器不会给出未使用功能
警告。
如何使GCC注意到未使用的函数 foo()
?
However, the compiler doesn't give an unused-function
warning.
What do I have to do to make GCC notice the unused function foo()
?
// main.cpp
void foo(){ } //should (but doesn't) trigger 'unused function' warning
int main (int argc, char **argv){
int x; //correctly triggers 'unused variable' warning
return 0;
}
请记住,我确实要未使用的功能警告。这不是不是如何摆脱警告问题。
Remember, I do want unused function warnings. This is not a "how do I get rid of warnings" question.
推荐答案
文档:
-Wunused-function:当声明了静态函数但未定义或未使用非内联静态函数时发出警告。此警告是由-Wall启用的
。
-Wunused-function: Warn whenever a static function is declared but not defined or a non-inline static function is unused. This warning is enabled by -Wall.
如您所见,您已经定义并声明了一个非静态的功能。此外,您的函数没有被内联(您需要使用 -O3
优化)。
As you can see, you've defined and declared a non-static function. Also your function isn't being inlined(for which you need to use -O3
optimization).
我不确定您要的内容是否存在于gcc中。 :-)但是它是开源的..也许您可以实现它?
I am not sure what you're asking for exists in gcc, as of yet. :-) But its open source.. maybe you can implement it?
这篇关于GCC -Wunused功能不起作用(但其他警告正在起作用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!