3 public class broken_cast
5 public static void report (string str)
7 throw new Exception (str);
10 public static void conv_ovf_i (long val, bool shouldThrow)
13 System.IntPtr x = (System.IntPtr) val;
15 report (String.Format ("conv_ovf_i did not throw for {0} ", val));
16 } catch (OverflowException exception) {
18 report (String.Format ("conv_ovf_i did throw for {0}", val));
22 public static void conv_ovf_i_un (long val, bool shouldThrow)
25 System.IntPtr x = (System.IntPtr) val;
27 report (String.Format ("conv_ovf_i_un did not throw for {0} ", val));
28 } catch (OverflowException exception) {
30 report (String.Format ("conv_ovf_i_un did throw for {0}", val));
34 public static void conv_ovf_u (long val, bool shouldThrow)
37 System.IntPtr x = (System.IntPtr) val;
39 report (String.Format ("conv_ovf_u did not throw for {0} ", val));
40 } catch (OverflowException exception) {
42 report (String.Format ("conv_ovf_u did throw for {0}", val));
46 public static void conv_ovf_u_un (long val, bool shouldThrow)
49 System.IntPtr x = (System.IntPtr) val;
51 report (String.Format ("conv_ovf_u_un did not throw for {0} ", val));
52 } catch (OverflowException exception) {
54 report (String.Format ("conv_ovf_u_un did throw for {0}", val));
58 public static int Main ()
62 long biggerThanI4 = int.MaxValue;
64 long smallerThanI4 = int.MinValue;
66 long biggerThanU4 = uint.MaxValue;
69 bool is32bits = IntPtr.Size == 4;
73 conv_ovf_i (ok_number, false);
75 conv_ovf_i (negative, false);
77 // conv_ovf_i (biggerThanI4, true && is32bits);
79 // conv_ovf_i (smallerThanI4, true && is32bits);
81 // conv_ovf_i (biggerThanU4, true && is32bits);
84 conv_ovf_i_un (ok_number, false);
86 conv_ovf_i_un (negative, false);
88 // conv_ovf_i_un (biggerThanI4, true && is32bits);
90 // conv_ovf_i_un (smallerThanI4, true && is32bits);
92 // conv_ovf_i_un (biggerThanU4, true && is32bits);
95 conv_ovf_u (ok_number, false);
97 conv_ovf_u (negative, false);
99 // conv_ovf_u (biggerThanI4, true && is32bits);
101 // conv_ovf_u (smallerThanI4, true && is32bits);
103 // conv_ovf_u (biggerThanU4, true && is32bits);
106 conv_ovf_u_un (ok_number, false);
108 conv_ovf_u_un (negative, false);
110 // conv_ovf_u_un (biggerThanI4, true && is32bits);
112 // conv_ovf_u_un (smallerThanI4, true && is32bits);
114 // conv_ovf_u_un (biggerThanU4, true && is32bits);
117 } catch (Exception e) {
118 Console.WriteLine (e);