Bug 4852 - no CS0649 warning is emitted for uninitialized structs
Summary: no CS0649 warning is emitted for uninitialized structs
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2012-05-02 20:44 UTC by Csaba Halász
Modified: 2012-05-21 08:12 UTC (History)
1 user (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Csaba Halász 2012-05-02 20:44:31 UTC
Given this sample code:

using System;

namespace Test
{
    public struct Bar
    {
        public int x;
    }
    public class TestClass
    {
        Bar b;
        int y;
        public bool Foo()
        {
            if (b.x == 0) return false;
            if (y == 0) return false;
            return true;
        }
        public static void Main(string[] args)
        {
        }
    }
}

mcs reports:
TestClass.cs(12,13): warning CS0649: Field `Test.TestClass.y' is never assigned to, and will always have its default value `0'
Compilation succeeded - 1 warning(s)

visual studio reports:
TestClass.cs(11,13): warning CS0649: Field 'Test.TestClass.b' is never assigned to, and will always have its default value 
TestClass.cs(12,13): warning CS0649: Field 'Test.TestClass.y' is never assigned to, and will always have its default value 0
Comment 1 Marek Safar 2012-05-21 08:12:52 UTC
Fixed in master