docs/compilers/CSharp/Warnversion Warning Waves.md
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/
The compiler shipped with .NET 11 (the C# 15 compiler) contains the following warnings which are reported only under /warn:11 or higher.
| Warning ID | Description |
|---|---|
| CS9368 | RequiresUnsafeAttribute is only valid under the updated memory safety rules |
| CS9377 | The 'unsafe' modifier does not have any effect here under the current rules |
The compiler shipped with .NET 10 (the C# 14 compiler) contains the following warnings which are reported only under /warn:10 or higher.
| Warning ID | Description |
|---|---|
| CS9265 | Field is never ref-assigned to, and will always have its default value (null reference) |
The compiler shipped with .NET 8 (the C# 12 compiler) contains the following warnings which are reported only under /warn:8 or higher.
| Warning ID | Description |
|---|---|
| CS9123 | Taking address of local or parameter in async method can create a GC hole |
| EnableGenerateDocumentationFile | Helper diagnostic for enforcing IDE0005 on build |
The compiler shipped with .NET 7 (the C# 11 compiler) contains the following warnings which are reported only under /warn:7 or higher.
| Warning ID | Description |
|---|---|
| CS8981 | Type names only containing lowercase ASCII characters may become reserved for the language |
The compiler shipped with .NET 6 (the C# 10 compiler) contains the following warnings which are reported only under /warn:6 or higher.
| Warning ID | Description |
|---|---|
| CS8826 | Partial method declarations have signature differences |
The compiler shipped with .NET 5 (the C# 9 compiler) contains the following warnings which are reported only under /warn:5 or higher.