diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 1999-07-27 12:42:43 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 1999-07-27 12:42:43 +0000 |
commit | 252aa0820e6bce274b33bd342cfc65e18a59a165 (patch) | |
tree | 1806e58de44b0a99806e6393ef563649f1e42438 /t | |
parent | 2cc242586845107754f99fa3e09637c9a344d545 (diff) | |
download | perl-252aa0820e6bce274b33bd342cfc65e18a59a165.tar.gz |
Integer constants (0x, 0[0-7], 0b) now overflow fatally,
they used to be just optional lexical warnings.
Also, with warnings turned on, constants > 2**32-1
trigger a non-portability warning.
p4raw-id: //depot/cfgperl@3798
Diffstat (limited to 't')
-rwxr-xr-x | t/op/oct.t | 44 | ||||
-rw-r--r-- | t/pragma/warn/6default | 11 | ||||
-rw-r--r-- | t/pragma/warn/util | 55 |
3 files changed, 56 insertions, 54 deletions
diff --git a/t/op/oct.t b/t/op/oct.t index 06bf8db660..c0613a92bf 100755 --- a/t/op/oct.t +++ b/t/op/oct.t @@ -1,15 +1,33 @@ #!./perl -print "1..11\n"; - -print +(oct('01234') == 01234) ? "ok" : "not ok", " 1\n"; -print +(oct('0x1234') == 0x1234) ? "ok" : "not ok", " 2\n"; -print +(hex('01234') == 0x1234) ? "ok" : "not ok", " 3\n"; -print +(oct('20000000000') == 020000000000) ? "ok" : "not ok", " 4\n"; -print +(oct('x80000000') == 0x80000000) ? "ok" : "not ok", " 5\n"; -print +(hex('80000000') == 0x80000000) ? "ok" : "not ok", " 6\n"; -print +(oct('1234') == 668) ? "ok" : "not ok", " 7\n"; -print +(hex('1234') == 4660) ? "ok" : "not ok", " 8\n"; -print +(hex('0x1234') == 0x1234) ? "ok" : "not ok", " 9\n"; -print +(oct('b11100') == 28) ? "ok" : "not ok", " 10\n"; -print +(oct('b101010') == 0b101010) ? "ok" : "not ok", " 11\n"; +print "1..24\n"; + +print +(oct('0b10101') == 0b10101) ? "ok" : "not ok", " 1\n"; +print +(oct('0b10101') == 025) ? "ok" : "not ok", " 2\n"; +print +(oct('0b10101') == 21) ? "ok" : "not ok", " 3\n"; +print +(oct('0b10101') == 0x15) ? "ok" : "not ok", " 4\n"; + +print +(oct('b10101') == 0b10101) ? "ok" : "not ok", " 5\n"; +print +(oct('b10101') == 025) ? "ok" : "not ok", " 6\n"; +print +(oct('b10101') == 21) ? "ok" : "not ok", " 7\n"; +print +(oct('b10101') == 0x15) ? "ok" : "not ok", " 8\n"; + +print +(oct('01234') == 0b1010011100) ? "ok" : "not ok", " 9\n"; +print +(oct('01234') == 01234) ? "ok" : "not ok", " 10\n"; +print +(oct('01234') == 668) ? "ok" : "not ok", " 11\n"; +print +(oct('01234') == 0x29c) ? "ok" : "not ok", " 12\n"; + +print +(oct('0x1234') == 0b1001000110100) ? "ok" : "not ok", " 13\n"; +print +(oct('0x1234') == 011064) ? "ok" : "not ok", " 14\n"; +print +(oct('0x1234') == 4660) ? "ok" : "not ok", " 15\n"; +print +(oct('0x1234') == 0x1234) ? "ok" : "not ok", " 16\n"; + +print +(hex('01234') == 0b1001000110100) ? "ok" : "not ok", " 17\n"; +print +(hex('01234') == 011064) ? "ok" : "not ok", " 18\n"; +print +(hex('01234') == 4660) ? "ok" : "not ok", " 19\n"; +print +(hex('01234') == 0x1234) ? "ok" : "not ok", " 20\n"; + +print +(hex('0x1234') == 0b1001000110100) ? "ok" : "not ok", " 21\n"; +print +(hex('0x1234') == 011064) ? "ok" : "not ok", " 22\n"; +print +(hex('0x1234') == 4660) ? "ok" : "not ok", " 23\n"; +print +(hex('0x1234') == 0x1234) ? "ok" : "not ok", " 24\n"; diff --git a/t/pragma/warn/6default b/t/pragma/warn/6default index c095b20827..be45c77777 100644 --- a/t/pragma/warn/6default +++ b/t/pragma/warn/6default @@ -11,24 +11,23 @@ Integer overflow in octal number at - line 3. no warning ; my $a = oct "7777777777777777777777777777777777779" ; EXPECT +Integer overflow in octal number at - line 3. ######## # all warning should be displayed use warning ; -my $a = oct "7777777777777777777777777777777777779" ; +my $a = oct "77777777797"; EXPECT -Integer overflow in octal number at - line 3. Illegal octal digit '9' ignored at - line 3. ######## # check scope use warning ; -my $a = oct "7777777777777777777777777777777777779" ; +my $a = oct "77777777797"; { no warning ; - my $a = oct "7777777777777777777777777777777777779" ; + my $b = oct "77777777797"; } my $c = oct "7777777777777777777777777777777777779" ; EXPECT -Integer overflow in octal number at - line 3. Illegal octal digit '9' ignored at - line 3. +Octal number > 037777777777 non-portable at - line 8. Integer overflow in octal number at - line 8. -Illegal octal digit '9' ignored at - line 8. diff --git a/t/pragma/warn/util b/t/pragma/warn/util index fc1e6dde3f..87d43e8ffc 100644 --- a/t/pragma/warn/util +++ b/t/pragma/warn/util @@ -3,7 +3,7 @@ Illegal octal digit ignored my $a = oct "029" ; - Illegal hex digit ignored + Illegal hexadecimal digit ignored my $a = hex "0xv9" ; Illegal binary digit ignored @@ -21,7 +21,7 @@ __END__ use warning 'octal' ; my $a = oct "029" ; no warning 'octal' ; -my $a = oct "029" ; +my $b = oct "029" ; EXPECT Illegal octal digit '9' ignored at - line 3. ######## @@ -42,62 +42,47 @@ EXPECT Illegal binary digit '9' ignored at - line 3. ######## # util.c -BEGIN { require Config ; import Config } -$^W =1 ; +$^W = 1 ; sub make_bin { "1" x $_[0] } -my $s = $Config{longsize}; -eval { pack "q", 0 }; eval { $s = length pack "q", 0 } unless $@; -$n = make_bin(8 * $s ) ; -$o = make_bin(8 * $s + 1) ; +$n = make_bin(33); { use warning 'unsafe' ; my $a = oct "0b$n" ; - my $b = oct "0b$o" ; no warning 'unsafe' ; - $b = oct "0b$o" ; + my $b = oct "0b$n" ; } -my $b = oct "0b$o" ; +my $c = oct "0b$n" ; EXPECT -Integer overflow in binary number at - line 12. -Integer overflow in binary number at - line 16. +Binary number > 0b11111111111111111111111111111111 non-portable at - line 7. +Binary number > 0b11111111111111111111111111111111 non-portable at - line 11. ######## # util.c -BEGIN { require Config ; import Config } -$^W =1 ; +$^W = 1 ; sub make_oct { ("","1","3")[$_[0]%3] . "7" x int($_[0]/3) } -my $s = $Config{longsize}; -eval { pack "q", 0 }; eval { $s = length pack "q", 0 } unless $@; -$n = make_oct(8 * $s ); -$o = make_oct(8 * $s + 1); +$n = make_oct(33); { use warning 'unsafe' ; my $a = oct "$n" ; - my $b = oct "$o" ; no warning 'unsafe' ; - $b = oct "$o" ; + my $b = oct "$n" ; } -my $b = oct "$o" ; +my $c = oct "$n" ; EXPECT -Integer overflow in octal number at - line 12. -Integer overflow in octal number at - line 16. +Octal number > 037777777777 non-portable at - line 7. +Octal number > 037777777777 non-portable at - line 11. ######## # util.c -BEGIN { require Config ; import Config } -$^W =1 ; +$^W = 1 ; sub make_hex { ("","1","3","7")[$_[0]%4] . "f" x int($_[0]/4) } -my $s = $Config{longsize}; -eval { pack "q", 0 }; eval { $s = length pack "q", 0 } unless $@; -$n = make_hex(8 * $s ) ; -$o = make_hex(8 * $s + 1) ; +$n = make_hex(33); { use warning 'unsafe' ; my $a = hex "$n" ; - my $b = hex "$o" ; no warning 'unsafe' ; - $b = hex "$o" ; + my $b = hex "$n" ; } -my $b = hex "$o" ; +my $c = hex "$n" ; EXPECT -Integer overflow in hexadecimal number at - line 12. -Integer overflow in hexadecimal number at - line 16. +Hexadecimal number > 0xffffffff non-portable at - line 7. +Hexadecimal number > 0xffffffff non-portable at - line 11. |