@@ -34,4 +34,46 @@ const _: () = if mem::size_of::<OverflowingEnum>() != 8 {
3434 unsafe { hint:: unreachable ( ) }
3535} ;
3636
37+ // Each value fits in i32 or u32, but not all values fit into the same type.
38+ // C compiler demo: <https://godbolt.org/z/GPYafPhjK>
39+ // FIXME: This seems to do the wrong thing for 32bit Linux?
40+ #[ repr( C ) ]
41+ #[ warn( overflowing_literals) ]
42+ enum OverflowingEnum2 {
43+ A = 4294967294 , // u32::MAX - 1
44+ //[linux32,msvc32,msvc64]~^ WARN: literal out of range
45+ B = -1 ,
46+ }
47+
48+ #[ cfg( not( linux64) ) ]
49+ const _: ( ) = if mem:: size_of :: < OverflowingEnum2 > ( ) != 4 {
50+ unsafe { hint:: unreachable ( ) }
51+ } ;
52+ #[ cfg( linux64) ]
53+ const _: ( ) = if mem:: size_of :: < OverflowingEnum2 > ( ) != 8 {
54+ unsafe { hint:: unreachable ( ) }
55+ } ;
56+
57+ // Force i32 or u32, respectively.
58+ // C compiler demo: <https://godbolt.org/z/bGss855a4>
59+ #[ repr( C ) ]
60+ enum I32Enum {
61+ A = 2147483647 , // i32::MAX
62+ B = -2147483647 ,
63+ }
64+ const _: ( ) = if mem:: size_of :: < I32Enum > ( ) != 4 {
65+ unsafe { hint:: unreachable ( ) }
66+ } ;
67+
68+ // C compiler demo: <https://godbolt.org/z/MeE9YGj4n>
69+ #[ repr( C ) ]
70+ #[ allow( overflowing_literals) ]
71+ enum U32Enum {
72+ A = 4294967295 , // u32::MAX
73+ B = 0 ,
74+ }
75+ const _: ( ) = if mem:: size_of :: < U32Enum > ( ) != 4 {
76+ unsafe { hint:: unreachable ( ) }
77+ } ;
78+
3779fn main ( ) { }
0 commit comments