简体   繁体   English

GCC:使用-Werror,但将特定错误降级为警告(在命令行中)

[英]GCC: Use -Werror but downgrade a specific error to a warning (in command-line)

An example: I'm using -Wall -Werror and -Werror . 一个示例:我正在使用-Wall -Werror-Werror This means unused static functions break the build. 这意味着未使用的static函数会破坏构建。 Clearly (?) unused functions are Bad, but if I'm working on code and it's in an intermediate state, want to be able to leave unused code in there. 显然(?)未使用的函数是错误的,但是如果我正在处理代码并且它处于中间状态,则希望能够将未使用的代码留在其中。 I can turn off the error with -Wno-unused-function , but then there's a risk that I'll finish what I'm working on, commit the code, and forget to remove the now-unused function. 我可以使用-Wno-unused-function来关闭错误,但是有可能会完成我正在处理的工作,提交代码,而忘记删除当前未使用的函数。

How can I set all warnings to errors with -Wall , but downgrade specific errors to warnings, without disabling them completely? 如何使用-Wall将所有警告设置为错误,但是将特定错误降级为警告,而又​​不完全禁用它们?

Use the -Wno-error= flags. 使用-Wno-error=标志。 In the example, the required flag would be -Wno-error=unused-function . 在此示例中,必需标志为-Wno-error=unused-function

PS: There are also pragmas for this purpose: http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html (my original question was "How can I do what these pragmas do, but in the command-line flags?" but I worked it out as I was asking it). PS:也有用于此目的的编译指示: http : //gcc.gnu.org/onlinedocs/gcc/Warning-Options.html (我最初的问题是“我该怎么做这些编译指示,但是在命令行中标记?”,但我按要求进行了求解)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM