Closed as duplicate
Closed as duplicate
Description
The following program throws DivideByZeroException
when optimizing and NullReferenceException
otherwise. The correct exception is DivideByZeroException
.
using System;
using System.Runtime.CompilerServices;
public unsafe class Program
{
public static void Main()
{
Foo(null, 0);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void Foo(C c, int x)
{
c.G = Test(1 / x);
}
public static Guid Test(int x)
{
return new Guid(x, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
class C
{
public Guid G;
}
}