Missing warning WRN_VolatileByRef for ref locals
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**:
**Steps to Reproduce**:
Compile the following code:
```csharp
using System;
var foo = new Foo();
foo.Do();
Console.WriteLine(foo.Do());
Console.WriteLine(foo.Do());
class Foo
{
public volatile int i;
public ref int Do()
{
ref var ix = ref i; //<-- I would expect a warning here!
ix += 10;
return ref ix;
}
}
```
When this code gets compiled no warning is issued. But the volatile read / write is ignored when done by ref.
A warning is only emitted when a volatile-field-ref is used as argument (see [CheckFieldAddress](https://github.com/dotnet/roslyn/blob/700a414453e2082dd2016b5655d3869387693e75/src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_Warnings.cs#L56))
**Expected Behavior**:
A warning should be emitted.
**Actual Behavior**:
No warning is emitted.
Contributor guide
Assessment
This issue has not been assessed yet.