Bug 35088 - Incorrect CS0420 warning when using volatile variable with Interlocked APIs
Summary: Incorrect CS0420 warning when using volatile variable with Interlocked APIs
Status: NEW
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-10-20 09:06 UTC by Alexander Köplinger [MSFT]
Modified: 2015-10-20 09:06 UTC (History)
1 user (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Alexander Köplinger [MSFT] 2015-10-20 09:06:22 UTC
Repro code:

> using System.Threading;
> 
> public class Test
> {
>    volatile int foo;
>    
>    void Bar()
>    {
>       Interlocked.CompareExchange(ref foo, 0, 1);
>    }
> }

Steps:

> mcs -t:library test.cs

Output:

> test.cs(9,39): warning CS0420: `Test.foo': A volatile field references will not be treated as volatile

According to https://msdn.microsoft.com/en-us/library/4bw5ewxy.aspx this warning shouldn't be raised when using the Interlocked.* APIs. csc and Roslyn don't generate a warning.

Nit: there's a typo in the warning message: "references" -> "reference"

Note You need to log in before you can comment on or make changes to this bug.