简体   繁体   中英

Set of Warnings as Error g++

I want to change the behavior of warnings and errors for my g++ compiler:

  • I want that normal warnings are spotted as errors ( -Werror )
  • I want extra warnings to be spotted. ( -Wall and -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 .
Is there some kind of alias for set of errors?

If you just give -Werror all warnings become errors. 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".

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 .

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. 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 ). The manual lists which warnings are enabled by -Wall -Wextra so it's a no-brainer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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