This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix the bin/oct/hex constant overflow tests for
[perl5.git] / t / pragma / warn / util
CommitLineData
599cee73
PM
1 util.c AOK
2
3 Illegal octal digit ignored
4 my $a = oct "029" ;
5
6 Illegal hex digit ignored
7 my $a = hex "0xv9" ;
8
4f19785b
WSI
9 Illegal binary digit ignored
10 my $a = oct "0b9" ;
599cee73 11
0453d815
PM
12
13 Mandatory Warnings
14 ------------------
15 Integer overflow in binary number
16 Integer overflow in octal number
17 Integer overflow in hex number
18
599cee73
PM
19__END__
20# util.c
21use warning 'octal' ;
22my $a = oct "029" ;
0453d815
PM
23no warning 'octal' ;
24my $a = oct "029" ;
599cee73 25EXPECT
399388f4 26Illegal octal digit '9' ignored at - line 3.
599cee73
PM
27########
28# util.c
29use warning 'unsafe' ;
30*a = hex "0xv9" ;
0453d815
PM
31no warning 'unsafe' ;
32*a = hex "0xv9" ;
599cee73 33EXPECT
651978e7 34Illegal hexadecimal digit 'v' ignored at - line 3.
4f19785b
WSI
35########
36# util.c
37use warning 'unsafe' ;
38*a = oct "0b9" ;
0453d815
PM
39no warning 'unsafe' ;
40*a = oct "0b9" ;
4f19785b 41EXPECT
399388f4 42Illegal binary digit '9' ignored at - line 3.
0453d815
PM
43########
44# util.c
651978e7 45BEGIN { require Config ; import Config }
0453d815 46$^W =1 ;
651978e7 47sub make_bin { "1" x $_[0] }
9f62e1ec
JH
48my $s = $Config{longsize};
49eval { pack "q", 0 }; eval { $s = length pack "q", 0 } unless $@;
50$n = make_bin(8 * $s ) ;
51$o = make_bin(8 * $s + 1) ;
0453d815
PM
52{
53 use warning 'unsafe' ;
651978e7
JH
54 my $a = oct "0b$n" ;
55 my $b = oct "0b$o" ;
0453d815 56 no warning 'unsafe' ;
651978e7 57 $b = oct "0b$o" ;
0453d815 58}
651978e7 59my $b = oct "0b$o" ;
0453d815 60EXPECT
9f62e1ec
JH
61Integer overflow in binary number at - line 12.
62Integer overflow in binary number at - line 16.
0453d815
PM
63########
64# util.c
651978e7 65BEGIN { require Config ; import Config }
0453d815 66$^W =1 ;
651978e7 67sub make_oct { ("","1","3")[$_[0]%3] . "7" x int($_[0]/3) }
9f62e1ec
JH
68my $s = $Config{longsize};
69eval { pack "q", 0 }; eval { $s = length pack "q", 0 } unless $@;
70$n = make_oct(8 * $s );
71$o = make_oct(8 * $s + 1);
0453d815
PM
72{
73 use warning 'unsafe' ;
651978e7
JH
74 my $a = oct "$n" ;
75 my $b = oct "$o" ;
0453d815 76 no warning 'unsafe' ;
651978e7 77 $b = oct "$o" ;
0453d815 78}
651978e7 79my $b = oct "$o" ;
0453d815 80EXPECT
9f62e1ec
JH
81Integer overflow in octal number at - line 12.
82Integer overflow in octal number at - line 16.
0453d815
PM
83########
84# util.c
651978e7 85BEGIN { require Config ; import Config }
0453d815 86$^W =1 ;
651978e7 87sub make_hex { ("","1","3","7")[$_[0]%4] . "f" x int($_[0]/4) }
9f62e1ec
JH
88my $s = $Config{longsize};
89eval { pack "q", 0 }; eval { $s = length pack "q", 0 } unless $@;
90$n = make_hex(8 * $s ) ;
91$o = make_hex(8 * $s + 1) ;
0453d815
PM
92{
93 use warning 'unsafe' ;
651978e7
JH
94 my $a = hex "$n" ;
95 my $b = hex "$o" ;
0453d815 96 no warning 'unsafe' ;
651978e7 97 $b = hex "$o" ;
0453d815 98}
651978e7 99my $b = hex "$o" ;
0453d815 100EXPECT
9f62e1ec
JH
101Integer overflow in hexadecimal number at - line 12.
102Integer overflow in hexadecimal number at - line 16.
0453d815 103