Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 910
Mario Corchero Avatar asked Feb 18 '13 09:02

Mario Corchero


People also ask

How do I disable all warnings being treated as errors?

You can make all warnings being treated as such using -Wno-error. You can make specific warnings being treated as such by using -Wno-error=<warning name> where <warning name> is the name of the warning you don't want treated as an error. If you want to entirely disable all warnings, use -w (not recommended).

How does GCC treat warning errors?

The warning is emitted only with --coverage enabled. By default, this warning is enabled and is treated as an error. -Wno-coverage-invalid-line-number can be used to disable the warning or -Wno-error=coverage-invalid-line-number can be used to disable the error. Suppress warning messages emitted by #warning directives.

How do you enable treatment warnings as a project error?

To find the "Treat warnings as errors" option, select the "Build" tab. Choose the "All" option to treat all warnings as errors. You can test the option by adding the following method to any class within your code and also adding a call to this method. All calls to obsolete methods cause a warning to be generated.

How do I turn off compiler warnings?

Turn off the warning for a project in Visual StudioSelect the Configuration Properties > C/C++ > Advanced property page. Edit the Disable Specific Warnings property to add 4996 .


1 Answers

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].

like image 53
Mats Petersson Avatar answered Sep 19 '22 03:09

Mats Petersson