Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignoring generated files when using "Treat warnings as errors"

We have started a new project but also have this problem for an existing project. The problem is that when we compile with a warning level of 4 we also want to switch on

'Treat all warnings as errors'

We are unable to do this at the moment because generated files (in particular reference.cs files) are missing things like XML comments and this generates a warning, we do not want to suppress the xml comment warnings totally out of all files just for specific types of files (namely generated code).

I have thought of a way this could be achieved but am not sure if these are the best way to do this or indeed where to start :) My thinking is that we need to do something with T4 templates for the code that is generated such that it does fill in XML documentation for generated code.

Does anyone have any ideas, currently I'm at well over 2k warnings (its a big project) :(

like image 676
krystan honour Avatar asked Apr 30 '10 08:04

krystan honour


People also ask

How do I stop treating warnings 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 ignore a warning when compiling?

Using legacy __attribute__ to provide more information to the compiler. Using _Pragma to suppress the warning. Using #pragma to suppress the warning. Using command line options to suppress the warning.

Should warnings be ignored C++?

Warnings must not be ignored. You'd better fix every possible error before starting software testing. You may waste much time and effort to find an error in the debugger, although the compiler gives you an explicit warning about it.

Can you ignore errors Visual Studio?

Suppress specific warnings for Visual C# or F# Or, select the project node and press Alt+Enter. Choose Build, and go to the Errors and warnings subsection. In the Suppress warnings or Suppress specific warnings box, specify the error codes of the warnings that you want to suppress, separated by semicolons.


1 Answers

You can selectively disable warnings with a pragma:

// Disable warning messages 4507 and 4034.
#pragma warning( disable : 4507 34 )

If you can emit such warnings (or an #include) in the generated code files, you're done.

Alternatively, you can disable them globally on the command-line for the compiler:

/wd4326 disables compiler warning C4326.

Then re-enable them (via a header file) in the files you want them for:

// Report warning 4326 as an error.
#pragma warning( error : 326 )

Finally, you can set different compile options for each source file by altering the Properties in the project file. Personally I find that a maintenance nightmare, but there are times you have no choice.

Edit: I see that your source files are C#, not C++.

Using the C# command-line:

to suppress CS0028, you could specify /nowarn:28.

Unfortunately, /warnaserror makes all warnings errors.

like image 171
egrunin Avatar answered Sep 16 '22 17:09

egrunin