Back to Roslyn

/warn warning "waves"

docs/compilers/CSharp/Warnversion Warning Waves.md

11.0.1004.9 KB
Original Source

/warn warning "waves"

The C# compiler flag /warn controls optional warnings. When we introduce new warnings that can be reported on existing code, we do so under an opt-in system so that programmers do not see new warnings without taking action to enable them. For that purpose, we have the compiler flag "/warn:n" where n is a whole number.

The default warning level when the command-line compiler is used is 4. If you want the compiler to produce all applicable warnings, you can specify /warn:9999.

In a typical project, this setting is controlled by the AnalysisLevel property, which determines the WarningLevel property (passed to the Csc task). For more information on AnalysisLevel, see https://devblogs.microsoft.com/dotnet/automatically-find-latent-bugs-in-your-code-with-net-5/

Warning level 11

The compiler shipped with .NET 11 (the C# 15 compiler) contains the following warnings which are reported only under /warn:11 or higher.

Warning IDDescription
CS9368RequiresUnsafeAttribute is only valid under the updated memory safety rules
CS9377The 'unsafe' modifier does not have any effect here under the current rules

Warning level 10

The compiler shipped with .NET 10 (the C# 14 compiler) contains the following warnings which are reported only under /warn:10 or higher.

Warning IDDescription
CS9265Field is never ref-assigned to, and will always have its default value (null reference)

Warning level 8

The compiler shipped with .NET 8 (the C# 12 compiler) contains the following warnings which are reported only under /warn:8 or higher.

Warning IDDescription
CS9123Taking address of local or parameter in async method can create a GC hole
EnableGenerateDocumentationFileHelper diagnostic for enforcing IDE0005 on build

Warning level 7

The compiler shipped with .NET 7 (the C# 11 compiler) contains the following warnings which are reported only under /warn:7 or higher.

Warning IDDescription
CS8981Type names only containing lowercase ASCII characters may become reserved for the language

Warning level 6

The compiler shipped with .NET 6 (the C# 10 compiler) contains the following warnings which are reported only under /warn:6 or higher.

Warning IDDescription
CS8826Partial method declarations have signature differences

Warning level 5

The compiler shipped with .NET 5 (the C# 9 compiler) contains the following warnings which are reported only under /warn:5 or higher.

Warning IDDescription
CS7023A static type is used in an 'is' or 'as' expression
CS8073Expression always true (or false) when comparing a struct to null
CS8848Diagnose precedence error with query expression
CS8880Struct constructor does not assign auto property (imported struct type with private fields)
CS8881Struct constructor does not assign field (imported struct type with private fields)
CS8882Out parameter not assigned (imported struct type with private fields)
CS8883Auto-property used before assigned in struct constructor (imported struct type with private fields)
CS8884Field used before assigned in struct constructor (imported struct type with private fields)
CS8885Struct constructor reads 'this' before assigning all fields (imported struct type with private fields)
CS8886Out parameter used before being assigned (imported struct type with private fields)
CS8887Local variable used before being assigned (imported struct type with private fields)
CS8892Multiple entry points
CS8897Static class used as the parameter type of a method in an interface type
CS8898Static class used as the return type of a method in an interface type