[Mono-bugs] [Bug 706877] New: Compiling with overflow checks enabled doesn't work

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Jul 19 18:59:56 EDT 2011


https://bugzilla.novell.com/show_bug.cgi?id=706877

https://bugzilla.novell.com/show_bug.cgi?id=706877#c0


           Summary: Compiling with overflow checks enabled doesn't work
    Classification: Mono
           Product: Mono: Compilers
           Version: 2.10.x
          Platform: i686
        OS/Version: Linux
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: C#
        AssignedTo: michael.miller at suse.com
        ReportedBy: martinho.fernandes at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Description of Problem:
When you compile a C# program with the gmcs flag -checked, no overflow checks
are made at runtime.

Steps to reproduce the problem:
1. Save the following program in a file a.cs:

public class Bug
{
    public static void Main()
    {
        long x = long.MaxValue;
        System.Console.WriteLine(x * 2);
    }
}

2. Compile with:
$ gmcs -checked a.cs

3. Run the resulting program:
$ mono a.exe

Actual Results:
The program prints -2.

Expected Results:
The program should throw an OverflowException.

How often does this happen? 
Always.

Additional Information:
The following program fails to compile with the error "error CS0220: The
operation overflows at compile time in checked mode":

public class Bug
{
    public static void Main()
    {
        System.Console.WriteLine(long.MaxValue * 2);
    }
}

The following program throws an OverflowException at runtime:


public class Bug
{
    public static void Main()
    {
        long x = long.MaxValue;
        checked
        {
            System.Console.WriteLine(x * 2);
        }
    }
}

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list