Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning as Error, but not all

Tags:

c#

I would like to enable Warning as Error on our current project/solution for obvious reasons.

There are several warnings that should NOT be handled as an error, eg Obsolete, and using #warning directives.

Is this possible?

I see that I can make specific warnings behave as errors, but I would really like the 'invert' of that.

The closest I can get is disabling the 2 above mentioned warnings, but then there will be no 'warning' for them either.

Any suggestions?

To clarify:

I want the warnings, just not as an error. So all warning except for the above mentioned exceptions will behave as an error, and the above mentioned will be warnings (ones I can see in the compiler results).

like image 493
leppie Avatar asked Apr 17 '09 11:04

leppie


People also ask

Should I treat warnings as errors?

Yes, even once in a while you will encounter the occasional warning you'd be better off leaving as a warning or even disabling completely. Those should be the exception to the rule, though. Here's some practical advise: at the start of a new project, start treating all warnings as errors, by default.

What is the difference between an error and a warning?

WARNING: Something has not worked as it should. This may be of greater or lesser importance depending on the circumstances. e.g. An input file was not found, or was of the wrong format. ERROR: Something ``serious'' has gone wrong.

How do I turn off 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 do you treat warning errors?

TreatWarningsAsErrors. The TreatWarningsAsErrors option treats all warnings as errors. You can also use the TreatWarningsAsErrors to set only some warnings as errors. If you turn on TreatWarningsAsErrors, you can use WarningsNotAsErrors to list warnings that shouldn't be treated as errors.


1 Answers

The warnaserror compiler option supports erroring only on specific warnings. You can thus specify all warnings to be shown as an error, then disable the errors for certain warnings. Using the page's example as a guide:

/warnaserror
/warnaserror-:642,649,652
like image 163
strager Avatar answered Oct 19 '22 05:10

strager