简体   繁体   English

一组警告作为错误g ++

[英]Set of Warnings as Error g++

I want to change the behavior of warnings and errors for my g++ compiler: 我想更改g ++编译器的警告和错误行为:

  • I want that normal warnings are spotted as errors ( -Werror ) 我希望将正常警告视为错误( -Werror
  • I want extra warnings to be spotted. 我想要发现额外的警告。 ( -Wall and -Wextra ) -Wall-Wextra

But my problem is that this way, all and extra warning are made errors. 但我的问题是这样,所有和额外的警告都会出错。 Is there a way to achieve what I want without needing to set a long list at -Werror=xxx,xxx,xxx . 有没有办法实现我想要的,而无需在-Werror=xxx,xxx,xxx设置长列表。
Is there some kind of alias for set of errors? 是否存在某种错误集的别名?

If you just give -Werror all warnings become errors. 如果您只是给-Werror所有警告都会出错。 Aside from listing the ones you (don't) want to make into errors as -W(no-)error=xxx , I don't believe there is a way to "make some warnings into errors". 除了列出你(不)想要犯错误的那些 - -W(no-)error=xxx ,我不相信有一种方法可以“对错误做出一些警告”。

Of course, one solution might be to compile the code twice - once with -Wall and -Wextra , and once with -Werror , but not -Wall and -Wextra . 当然,一个解决方案可能是编译代码两次 - 一次使用-Wall-Wextra ,一次使用-Werror ,但不是-Wall-Wextra

In the long term, I'm sure it will be worth the extra effort of marking which errors you (don't) want -Werror to see as errors [although I'd say the better solution is probably to use -Wno-xxx, to disable any warnings that you deem acceptable, as opposed to "warn but don't make it an error" - after all, the purpose of -Werror in my view is to prevent code from being submitted to a project with warnings in it - and that should mean one of two things: the warning is fixed, or the warning is disabled. 从长远来看,我确信值得花费额外的努力来标记你(不)想要哪些错误 - 错误-Werror [虽然我会说更好的解决方案可能是使用-Wno-xxx ,禁用任何你认为可接受的警告,而不是“警告但不要使它成为错误” - 毕竟,我认为-Werror的目的是防止代码被提交到带有警告的项目中 - 这应该意味着两件事之一:警告是固定的,或警告被禁用。 Whichever makes sense for that project]. 无论哪个对该项目有意义]。

Rather than using -Werror=... with a long list of warnings you can use -Werror -Wno-error=... with a much shorter list of warnings (only the ones enabled by -Wall -Wextra ). 您可以使用-Werror -Wno-error=...而使用更短的警告列表(仅使用-Wall -Wextra启用的警告列表),而不是使用-Werror=... The manual lists which warnings are enabled by -Wall -Wextra so it's a no-brainer. 手册列出了-Wall -Wextra启用了哪些警告,所以这是一个明智的选择。

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

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