1 op.c AOK 2 3 Found = in conditional, should be == 4 1 if $a = 1 ; 5 6 Useless use of time in void context 7 Useless use of a variable in void context 8 Useless use of a constant in void context 9 time ; 10 $a ; 11 "abc" 12 13 Useless use of sort in scalar context 14 my $x = sort (2,1,3); 15 16 Applying %s to %s will act on scalar(%s) 17 my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; 18 @a =~ /abc/ ; 19 @a =~ s/a/b/ ; 20 @a =~ tr/a/b/ ; 21 @$b =~ /abc/ ; 22 @$b =~ s/a/b/ ; 23 @$b =~ tr/a/b/ ; 24 %a =~ /abc/ ; 25 %a =~ s/a/b/ ; 26 %a =~ tr/a/b/ ; 27 %$c =~ /abc/ ; 28 %$c =~ s/a/b/ ; 29 %$c =~ tr/a/b/ ; 30 31 32 Parentheses missing around "my" list at -e line 1. 33 my $a, $b = (1,2); 34 35 Parentheses missing around "local" list at -e line 1. 36 local $a, $b = (1,2); 37 38 Bareword found in conditional at -e line 1. 39 use warnings 'bareword'; my $x = print(ABC || 1); 40 41 Value of %s may be \"0\"; use \"defined\" 42 $x = 1 if $x = <FH> ; 43 $x = 1 while $x = <FH> ; 44 45 Subroutine fred redefined at -e line 1. 46 sub fred{1;} sub fred{1;} 47 48 Constant subroutine %s redefined 49 sub fred() {1;} sub fred() {1;} 50 51 Format FRED redefined at /tmp/x line 5. 52 format FRED = 53 . 54 format FRED = 55 . 56 57 Array @%s missing the @ in argument %d of %s() 58 push fred ; 59 60 Hash %%%s missing the %% in argument %d of %s() 61 keys joe ; 62 63 Statement unlikely to be reached 64 (Maybe you meant system() when you said exec()? 65 exec "true" ; my $a 66 67 defined(@array) is deprecated 68 (Maybe you should just omit the defined()?) 69 my @a ; defined @a ; 70 defined (@a = (1,2,3)) ; 71 72 defined(%hash) is deprecated 73 (Maybe you should just omit the defined()?) 74 my %h ; defined %h ; 75 76 $[ used in comparison (did you mean $] ?) 77 78 length() used on @array (did you mean "scalar(@array)"?) 79 length() used on %hash (did you mean "scalar(keys %hash)"?) 80 81 /---/ should probably be written as "---" 82 join(/---/, @foo); 83 84 %s() called too early to check prototype [Perl_peep] 85 fred() ; sub fred ($$) {} 86 87 88 Package '%s' not found (did you use the incorrect case?) 89 90 Use of /g modifier is meaningless in split 91 92 Possible precedence problem on bitwise %c operator [Perl_ck_bitop] 93 94 Mandatory Warnings 95 ------------------ 96 Prototype mismatch: [cv_ckproto] 97 sub fred() ; 98 sub fred($) {} 99 100 Runaway prototype [newSUB] TODO 101 oops: oopsAV [oopsAV] TODO 102 oops: oopsHV [oopsHV] TODO 103 104__END__ 105# op.c 106use warnings 'syntax' ; 1071 if $a = 1 ; 108no warnings 'syntax' ; 1091 if $a = 1 ; 110EXPECT 111Found = in conditional, should be == at - line 3. 112######## 113# op.c 114use warnings 'syntax' ; 115use constant foo => 1; 1161 if $a = foo ; 117no warnings 'syntax' ; 1181 if $a = foo ; 119EXPECT 120######## 121# op.c 122my (@foo, %foo); 123%main::foo->{"bar"}; 124%foo->{"bar"}; 125@main::foo->[23]; 126@foo->[23]; 127$main::foo = {}; %$main::foo->{"bar"}; 128$foo = {}; %$foo->{"bar"}; 129$main::foo = []; @$main::foo->[34]; 130$foo = []; @$foo->[34]; 131no warnings 'deprecated'; 132%main::foo->{"bar"}; 133%foo->{"bar"}; 134@main::foo->[23]; 135@foo->[23]; 136$main::foo = {}; %$main::foo->{"bar"}; 137$foo = {}; %$foo->{"bar"}; 138$main::foo = []; @$main::foo->[34]; 139$foo = []; @$foo->[34]; 140EXPECT 141Using a hash as a reference is deprecated at - line 3. 142Using a hash as a reference is deprecated at - line 4. 143Using an array as a reference is deprecated at - line 5. 144Using an array as a reference is deprecated at - line 6. 145Using a hash as a reference is deprecated at - line 7. 146Using a hash as a reference is deprecated at - line 8. 147Using an array as a reference is deprecated at - line 9. 148Using an array as a reference is deprecated at - line 10. 149######## 150# op.c 151use warnings 'void' ; close STDIN ; 1521 x 3 ; # OP_REPEAT 153 # OP_GVSV 154wantarray ; # OP_WANTARRAY 155 # OP_GV 156 # OP_PADSV 157 # OP_PADAV 158 # OP_PADHV 159 # OP_PADANY 160 # OP_AV2ARYLEN 161ref ; # OP_REF 162\@a ; # OP_REFGEN 163\$a ; # OP_SREFGEN 164defined $a ; # OP_DEFINED 165hex $a ; # OP_HEX 166oct $a ; # OP_OCT 167length $a ; # OP_LENGTH 168substr $a,1 ; # OP_SUBSTR 169vec $a,1,2 ; # OP_VEC 170index $a,1,2 ; # OP_INDEX 171rindex $a,1,2 ; # OP_RINDEX 172sprintf $a ; # OP_SPRINTF 173$a[0] ; # OP_AELEM 174 # OP_AELEMFAST 175@a[0] ; # OP_ASLICE 176#values %a ; # OP_VALUES 177#keys %a ; # OP_KEYS 178$a{0} ; # OP_HELEM 179@a{0} ; # OP_HSLICE 180unpack "a", "a" ; # OP_UNPACK 181pack $a,"" ; # OP_PACK 182join "" ; # OP_JOIN 183(@a)[0,1] ; # OP_LSLICE 184 # OP_ANONLIST 185 # OP_ANONHASH 186sort(1,2) ; # OP_SORT 187reverse(1,2) ; # OP_REVERSE 188 # OP_RANGE 189 # OP_FLIP 190(1 ..2) ; # OP_FLOP 191caller ; # OP_CALLER 192fileno STDIN ; # OP_FILENO 193eof STDIN ; # OP_EOF 194tell STDIN ; # OP_TELL 195readlink 1; # OP_READLINK 196time ; # OP_TIME 197localtime ; # OP_LOCALTIME 198gmtime ; # OP_GMTIME 199eval { getgrnam 1 }; # OP_GGRNAM 200eval { getgrgid 1 }; # OP_GGRGID 201eval { getpwnam 1 }; # OP_GPWNAM 202eval { getpwuid 1 }; # OP_GPWUID 203prototype "foo"; # OP_PROTOTYPE 204$a ~~ $b; # OP_SMARTMATCH 205$a <=> $b; # OP_NCMP 206use 5.015; 207__SUB__ # OP_RUNCV 208EXPECT 209Useless use of repeat (x) in void context at - line 3. 210Useless use of wantarray in void context at - line 5. 211Useless use of reference-type operator in void context at - line 12. 212Useless use of reference constructor in void context at - line 13. 213Useless use of single ref constructor in void context at - line 14. 214Useless use of defined operator in void context at - line 15. 215Useless use of hex in void context at - line 16. 216Useless use of oct in void context at - line 17. 217Useless use of length in void context at - line 18. 218Useless use of substr in void context at - line 19. 219Useless use of vec in void context at - line 20. 220Useless use of index in void context at - line 21. 221Useless use of rindex in void context at - line 22. 222Useless use of sprintf in void context at - line 23. 223Useless use of array element in void context at - line 24. 224Useless use of array slice in void context at - line 26. 225Useless use of hash element in void context at - line 29. 226Useless use of hash slice in void context at - line 30. 227Useless use of unpack in void context at - line 31. 228Useless use of pack in void context at - line 32. 229Useless use of join or string in void context at - line 33. 230Useless use of list slice in void context at - line 34. 231Useless use of sort in void context at - line 37. 232Useless use of reverse in void context at - line 38. 233Useless use of range (or flop) in void context at - line 41. 234Useless use of caller in void context at - line 42. 235Useless use of fileno in void context at - line 43. 236Useless use of eof in void context at - line 44. 237Useless use of tell in void context at - line 45. 238Useless use of readlink in void context at - line 46. 239Useless use of time in void context at - line 47. 240Useless use of localtime in void context at - line 48. 241Useless use of gmtime in void context at - line 49. 242Useless use of getgrnam in void context at - line 50. 243Useless use of getgrgid in void context at - line 51. 244Useless use of getpwnam in void context at - line 52. 245Useless use of getpwuid in void context at - line 53. 246Useless use of subroutine prototype in void context at - line 54. 247Useless use of smart match in void context at - line 55. 248Useless use of numeric comparison (<=>) in void context at - line 56. 249Useless use of __SUB__ in void context at - line 58. 250######## 251# op.c 252use warnings 'void' ; close STDIN ; 253my $x = sort (2,1,3); 254no warnings 'void' ; 255$x = sort (2,1,3); 256EXPECT 257Useless use of sort in scalar context at - line 3. 258######## 259# op.c 260no warnings 'void' ; close STDIN ; 2611 x 3 ; # OP_REPEAT 262 # OP_GVSV 263wantarray ; # OP_WANTARRAY 264 # OP_GV 265 # OP_PADSV 266 # OP_PADAV 267 # OP_PADHV 268 # OP_PADANY 269 # OP_AV2ARYLEN 270ref ; # OP_REF 271\@a ; # OP_REFGEN 272\$a ; # OP_SREFGEN 273defined $a ; # OP_DEFINED 274hex $a ; # OP_HEX 275oct $a ; # OP_OCT 276length $a ; # OP_LENGTH 277substr $a,1 ; # OP_SUBSTR 278vec $a,1,2 ; # OP_VEC 279index $a,1,2 ; # OP_INDEX 280rindex $a,1,2 ; # OP_RINDEX 281sprintf $a ; # OP_SPRINTF 282$a[0] ; # OP_AELEM 283 # OP_AELEMFAST 284@a[0] ; # OP_ASLICE 285#values %a ; # OP_VALUES 286#keys %a ; # OP_KEYS 287$a{0} ; # OP_HELEM 288@a{0} ; # OP_HSLICE 289unpack "a", "a" ; # OP_UNPACK 290pack $a,"" ; # OP_PACK 291join "" ; # OP_JOIN 292(@a)[0,1] ; # OP_LSLICE 293 # OP_ANONLIST 294 # OP_ANONHASH 295sort(1,2) ; # OP_SORT 296reverse(1,2) ; # OP_REVERSE 297 # OP_RANGE 298 # OP_FLIP 299(1 ..2) ; # OP_FLOP 300caller ; # OP_CALLER 301fileno STDIN ; # OP_FILENO 302eof STDIN ; # OP_EOF 303tell STDIN ; # OP_TELL 304readlink 1; # OP_READLINK 305time ; # OP_TIME 306localtime ; # OP_LOCALTIME 307gmtime ; # OP_GMTIME 308eval { getgrnam 1 }; # OP_GGRNAM 309eval { getgrgid 1 }; # OP_GGRGID 310eval { getpwnam 1 }; # OP_GPWNAM 311eval { getpwuid 1 }; # OP_GPWUID 312prototype "foo"; # OP_PROTOTYPE 313EXPECT 314######## 315# op.c 316use warnings 'void' ; 317for (@{[0]}) { "$_" } # check warning isn't duplicated 318no warnings 'void' ; 319for (@{[0]}) { "$_" } # check warning isn't duplicated 320EXPECT 321Useless use of string in void context at - line 3. 322######## 323# op.c 324use warnings 'void' ; 325use Config ; 326BEGIN { 327 if ( ! $Config{d_telldir}) { 328 print <<EOM ; 329SKIPPED 330# telldir not present 331EOM 332 exit 333 } 334} 335telldir 1 ; # OP_TELLDIR 336no warnings 'void' ; 337telldir 1 ; # OP_TELLDIR 338EXPECT 339Useless use of telldir in void context at - line 13. 340######## 341# op.c 342use warnings 'void' ; 343use Config ; 344BEGIN { 345 if ( ! $Config{d_getppid}) { 346 print <<EOM ; 347SKIPPED 348# getppid not present 349EOM 350 exit 351 } 352} 353getppid ; # OP_GETPPID 354no warnings 'void' ; 355getppid ; # OP_GETPPID 356EXPECT 357Useless use of getppid in void context at - line 13. 358######## 359# op.c 360use warnings 'void' ; 361use Config ; 362BEGIN { 363 if ( ! $Config{d_getpgrp}) { 364 print <<EOM ; 365SKIPPED 366# getpgrp not present 367EOM 368 exit 369 } 370} 371getpgrp ; # OP_GETPGRP 372no warnings 'void' ; 373getpgrp ; # OP_GETPGRP 374EXPECT 375Useless use of getpgrp in void context at - line 13. 376######## 377# op.c 378use warnings 'void' ; 379use Config ; 380BEGIN { 381 if ( ! $Config{d_times}) { 382 print <<EOM ; 383SKIPPED 384# times not present 385EOM 386 exit 387 } 388} 389times ; # OP_TMS 390no warnings 'void' ; 391times ; # OP_TMS 392EXPECT 393Useless use of times in void context at - line 13. 394######## 395# op.c 396use warnings 'void' ; 397use Config ; 398BEGIN { 399 if ( ! $Config{d_getprior} or $^O eq 'os2') { # Locks before fixpak22 400 print <<EOM ; 401SKIPPED 402# getpriority not present 403EOM 404 exit 405 } 406} 407getpriority 1,2; # OP_GETPRIORITY 408no warnings 'void' ; 409getpriority 1,2; # OP_GETPRIORITY 410EXPECT 411Useless use of getpriority in void context at - line 13. 412######## 413# op.c 414use warnings 'void' ; 415use Config ; 416BEGIN { 417 if ( ! $Config{d_getlogin}) { 418 print <<EOM ; 419SKIPPED 420# getlogin not present 421EOM 422 exit 423 } 424} 425getlogin ; # OP_GETLOGIN 426no warnings 'void' ; 427getlogin ; # OP_GETLOGIN 428EXPECT 429Useless use of getlogin in void context at - line 13. 430######## 431# op.c 432use warnings 'void' ; 433use Config ; BEGIN { 434if ( ! $Config{d_socket}) { 435 print <<EOM ; 436SKIPPED 437# getsockname not present 438# getpeername not present 439# gethostbyname not present 440# gethostbyaddr not present 441# gethostent not present 442# getnetbyname not present 443# getnetbyaddr not present 444# getnetent not present 445# getprotobyname not present 446# getprotobynumber not present 447# getprotoent not present 448# getservbyname not present 449# getservbyport not present 450# getservent not present 451EOM 452 exit 453} } 454getsockname STDIN ; # OP_GETSOCKNAME 455getpeername STDIN ; # OP_GETPEERNAME 456gethostbyname 1 ; # OP_GHBYNAME 457gethostbyaddr 1,2; # OP_GHBYADDR 458gethostent ; # OP_GHOSTENT 459getnetbyname 1 ; # OP_GNBYNAME 460getnetbyaddr 1,2 ; # OP_GNBYADDR 461getnetent ; # OP_GNETENT 462getprotobyname 1; # OP_GPBYNAME 463getprotobynumber 1; # OP_GPBYNUMBER 464getprotoent ; # OP_GPROTOENT 465getservbyname 1,2; # OP_GSBYNAME 466getservbyport 1,2; # OP_GSBYPORT 467getservent ; # OP_GSERVENT 468 469no warnings 'void' ; 470getsockname STDIN ; # OP_GETSOCKNAME 471getpeername STDIN ; # OP_GETPEERNAME 472gethostbyname 1 ; # OP_GHBYNAME 473gethostbyaddr 1,2; # OP_GHBYADDR 474gethostent ; # OP_GHOSTENT 475getnetbyname 1 ; # OP_GNBYNAME 476getnetbyaddr 1,2 ; # OP_GNBYADDR 477getnetent ; # OP_GNETENT 478getprotobyname 1; # OP_GPBYNAME 479getprotobynumber 1; # OP_GPBYNUMBER 480getprotoent ; # OP_GPROTOENT 481getservbyname 1,2; # OP_GSBYNAME 482getservbyport 1,2; # OP_GSBYPORT 483getservent ; # OP_GSERVENT 484INIT { 485 # some functions may not be there, so we exit without running 486 exit; 487} 488EXPECT 489Useless use of getsockname in void context at - line 24. 490Useless use of getpeername in void context at - line 25. 491Useless use of gethostbyname in void context at - line 26. 492Useless use of gethostbyaddr in void context at - line 27. 493Useless use of gethostent in void context at - line 28. 494Useless use of getnetbyname in void context at - line 29. 495Useless use of getnetbyaddr in void context at - line 30. 496Useless use of getnetent in void context at - line 31. 497Useless use of getprotobyname in void context at - line 32. 498Useless use of getprotobynumber in void context at - line 33. 499Useless use of getprotoent in void context at - line 34. 500Useless use of getservbyname in void context at - line 35. 501Useless use of getservbyport in void context at - line 36. 502Useless use of getservent in void context at - line 37. 503######## 504# op.c 505use warnings 'void' ; 506*a ; # OP_RV2GV 507$a ; # OP_RV2SV 508@a ; # OP_RV2AV 509%a ; # OP_RV2HV 510no warnings 'void' ; 511*a ; # OP_RV2GV 512$a ; # OP_RV2SV 513@a ; # OP_RV2AV 514%a ; # OP_RV2HV 515EXPECT 516Useless use of a variable in void context at - line 3. 517Useless use of a variable in void context at - line 4. 518Useless use of a variable in void context at - line 5. 519Useless use of a variable in void context at - line 6. 520######## 521# op.c 522use warnings 'void' ; 523"abc"; # OP_CONST 5247 ; # OP_CONST 525"x" . "y"; # optimized to OP_CONST 5262 + 2; # optimized to OP_CONST 527use constant U => undef; 528U; 529qq/" \n/; 5305 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT 531print "boo\n" if U; # test OPpCONST_SHORTCIRCUIT 532no warnings 'void' ; 533"abc"; # OP_CONST 5347 ; # OP_CONST 535"x" . "y"; # optimized to OP_CONST 5362 + 2; # optimized to OP_CONST 537EXPECT 538Useless use of a constant ("abc") in void context at - line 3. 539Useless use of a constant (7) in void context at - line 4. 540Useless use of a constant ("xy") in void context at - line 5. 541Useless use of a constant (4) in void context at - line 6. 542Useless use of a constant (undef) in void context at - line 8. 543Useless use of a constant ("\"\t\n") in void context at - line 9. 544######## 545# op.c 546use utf8; 547use open qw( :utf8 :std ); 548use warnings 'void' ; 549"àḆc"; # OP_CONST 550"Ẋ" . "ƴ"; # optimized to OP_CONST 551FOO; # Bareword optimized to OP_CONST 552use constant ů => undef; 553ů; 5545 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT 555print "boo\n" if ů; # test OPpCONST_SHORTCIRCUIT 556no warnings 'void' ; 557"àḆc"; # OP_CONST 558"Ẋ" . "ƴ"; # optimized to OP_CONST 559EXPECT 560Useless use of a constant ("\340\x{1e06}c") in void context at - line 5. 561Useless use of a constant ("\x{1e8a}\x{1b4}") in void context at - line 6. 562Useless use of a constant ("\x{ff26}\x{ff2f}\x{ff2f}") in void context at - line 7. 563Useless use of a constant (undef) in void context at - line 9. 564######## 565# op.c 566# 567use warnings 'misc' ; 568my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;my $d = 'test'; 569@a =~ /abc/ ; 570@a2 =~ s/a/b/ ; 571@a3 =~ tr/a/b/ ; 572@$b =~ /abc/ ; 573@$b =~ s/a/b/ ; 574@$b =~ tr/a/b/ ; 575%a =~ /abc/ ; 576%a2 =~ s/a/b/ ; 577%a3 =~ tr/a/b/ ; 578%$c =~ /abc/ ; 579%$c =~ s/a/b/ ; 580%$c =~ tr/a/b/ ; 581$d =~ tr/a/b/d ; 582$d2 =~ tr/a/bc/; 583{ 584no warnings 'misc' ; 585my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; my $d = 'test'; 586@a =~ /abc/ ; 587@a =~ s/a/b/ ; 588@a =~ tr/a/b/ ; 589@$b =~ /abc/ ; 590@$b =~ s/a/b/ ; 591@$b =~ tr/a/b/ ; 592%a =~ /abc/ ; 593%a =~ s/a/b/ ; 594%a =~ tr/a/b/ ; 595%$c =~ /abc/ ; 596%$c =~ s/a/b/ ; 597%$c =~ tr/a/b/ ; 598$d =~ tr/a/b/d ; 599$d =~ tr/a/bc/ ; 600} 601EXPECT 602Applying pattern match (m//) to @a will act on scalar(@a) at - line 5. 603Applying substitution (s///) to @a2 will act on scalar(@a2) at - line 6. 604Applying transliteration (tr///) to @a3 will act on scalar(@a3) at - line 7. 605Applying pattern match (m//) to @array will act on scalar(@array) at - line 8. 606Applying substitution (s///) to @array will act on scalar(@array) at - line 9. 607Applying transliteration (tr///) to @array will act on scalar(@array) at - line 10. 608Applying pattern match (m//) to %a will act on scalar(%a) at - line 11. 609Applying substitution (s///) to %a2 will act on scalar(%a2) at - line 12. 610Applying transliteration (tr///) to %a3 will act on scalar(%a3) at - line 13. 611Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 14. 612Applying substitution (s///) to %hash will act on scalar(%hash) at - line 15. 613Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 16. 614Useless use of /d modifier in transliteration operator at - line 17. 615Replacement list is longer than search list at - line 18. 616Can't modify array dereference in substitution (s///) at - line 6, near "s/a/b/ ;" 617BEGIN not safe after errors--compilation aborted at - line 20. 618######## 619# op.c 620use warnings 'parenthesis' ; 621my $a, $b = (1,2); 622my @foo,%bar, $quux; # there's a TAB here 623my $x, $y or print; 624no warnings 'parenthesis' ; 625my $c, $d = (1,2); 626EXPECT 627Parentheses missing around "my" list at - line 3. 628Parentheses missing around "my" list at - line 4. 629######## 630# op.c 631use warnings 'parenthesis' ; 632our $a, $b = (1,2); 633no warnings 'parenthesis' ; 634our $c, $d = (1,2); 635EXPECT 636Parentheses missing around "our" list at - line 3. 637######## 638# op.c 639use warnings 'parenthesis' ; 640local $a, $b = (1,2); 641local *f, *g; 642no warnings 'parenthesis' ; 643local $c, $d = (1,2); 644EXPECT 645Parentheses missing around "local" list at - line 3. 646Parentheses missing around "local" list at - line 4. 647######## 648# op.c 649use warnings 'bareword' ; 650print (ABC || 1) ; 651no warnings 'bareword' ; 652print (ABC || 1) ; 653EXPECT 654Bareword found in conditional at - line 3. 655######## 656--FILE-- abc 657 658--FILE-- 659# op.c 660use warnings 'misc' ; 661open FH, "<abc" ; 662$x = 1 if $x = <FH> ; 663no warnings 'misc' ; 664$x = 1 if $x = <FH> ; 665EXPECT 666Value of <HANDLE> construct can be "0"; test with defined() at - line 4. 667######## 668# op.c 669use warnings 'misc' ; 670opendir FH, "." ; 671$x = 1 if $x = readdir FH ; 672no warnings 'misc' ; 673$x = 1 if $x = readdir FH ; 674closedir FH ; 675EXPECT 676Value of readdir() operator can be "0"; test with defined() at - line 4. 677######## 678# op.c 679use warnings 'misc' ; 680$x = 1 if $x = <*> ; 681no warnings 'misc' ; 682$x = 1 if $x = <*> ; 683EXPECT 684Value of glob construct can be "0"; test with defined() at - line 3. 685######## 686# op.c 687use warnings 'misc' ; 688%a = (1,2,3,4) ; 689$x = 1 if $x = each %a ; 690no warnings 'misc' ; 691$x = 1 if $x = each %a ; 692EXPECT 693Value of each() operator can be "0"; test with defined() at - line 4. 694######## 695# op.c 696use warnings 'misc' ; 697$x = 1 while $x = <*> and 0 ; 698no warnings 'misc' ; 699$x = 1 while $x = <*> and 0 ; 700EXPECT 701Value of glob construct can be "0"; test with defined() at - line 3. 702######## 703# op.c 704use warnings 'misc' ; 705opendir FH, "." ; 706$x = 1 while $x = readdir FH and 0 ; 707no warnings 'misc' ; 708$x = 1 while $x = readdir FH and 0 ; 709closedir FH ; 710EXPECT 711Value of readdir() operator can be "0"; test with defined() at - line 4. 712######## 713# op.c 714use warnings 'misc'; 715open FH, "<abc"; 716($_ = <FH>) // ($_ = 1); 717opendir DH, "."; 718%a = (1,2,3,4) ; 719EXPECT 720######## 721# op.c 722use warnings 'redefine' ; 723sub fred {} 724sub fred {} 725no warnings 'redefine' ; 726sub fred {} 727EXPECT 728Subroutine fred redefined at - line 4. 729######## 730# op.c 731use warnings 'redefine' ; 732sub fred () { 1 } 733sub fred () { 1 } 734no warnings 'redefine' ; 735sub fred () { 1 } 736EXPECT 737Constant subroutine fred redefined at - line 4. 738######## 739# op.c 740sub fred () { 1 } 741sub fred () { 2 } 742EXPECT 743Constant subroutine fred redefined at - line 3. 744######## 745# op.c 746sub fred () { 1 } 747*fred = sub () { 2 }; 748EXPECT 749Constant subroutine main::fred redefined at - line 3. 750######## 751# op.c 752no warnings 'redefine' ; 753sub fred () { 1 } 754sub fred () { 2 } 755EXPECT 756######## 757# op.c 758no warnings 'redefine' ; 759sub fred () { 1 } 760*fred = sub () { 2 }; 761EXPECT 762######## 763# op.c 764use warnings 'redefine' ; 765format FRED = 766. 767format FRED = 768. 769no warnings 'redefine' ; 770format FRED = 771. 772EXPECT 773Format FRED redefined at - line 5. 774######## 775# op.c 776push FRED; 777no warnings 'deprecated' ; 778push FRED; 779EXPECT 780Array @FRED missing the @ in argument 1 of push() at - line 2. 781######## 782# op.c 783@a = keys FRED ; 784no warnings 'deprecated' ; 785@a = keys FRED ; 786EXPECT 787Hash %FRED missing the % in argument 1 of keys() at - line 2. 788######## 789# op.c 790use warnings 'syntax' ; 791exec "$^X -e 1" ; 792my $a 793EXPECT 794Statement unlikely to be reached at - line 4. 795 (Maybe you meant system() when you said exec()?) 796######## 797# op.c, no warning if exec isn't a statement. 798use warnings 'syntax' ; 799$a || exec "$^X -e 1" ; 800my $a 801EXPECT 802######## 803# op.c 804defined(@a); 805EXPECT 806defined(@array) is deprecated at - line 2. 807 (Maybe you should just omit the defined()?) 808######## 809# op.c 810my @a; defined(@a); 811EXPECT 812defined(@array) is deprecated at - line 2. 813 (Maybe you should just omit the defined()?) 814######## 815# op.c 816defined(@a = (1,2,3)); 817EXPECT 818defined(@array) is deprecated at - line 2. 819 (Maybe you should just omit the defined()?) 820######## 821# op.c 822defined(%h); 823EXPECT 824defined(%hash) is deprecated at - line 2. 825 (Maybe you should just omit the defined()?) 826######## 827# op.c 828my %h; defined(%h); 829EXPECT 830defined(%hash) is deprecated at - line 2. 831 (Maybe you should just omit the defined()?) 832######## 833# op.c 834no warnings 'syntax' ; 835exec "$^X -e 1" ; 836my $a 837EXPECT 838 839######## 840# op.c 841sub fred(); 842sub fred($) {} 843EXPECT 844Prototype mismatch: sub main::fred () vs ($) at - line 3. 845######## 846# op.c 847use utf8; 848use open qw( :utf8 :std ); 849sub frèd(); 850sub frèd($) {} 851EXPECT 852Prototype mismatch: sub main::frèd () vs ($) at - line 5. 853######## 854# op.c 855use utf8; 856use open qw( :utf8 :std ); 857use warnings; 858eval "sub fòò (\$\0) {}"; 859EXPECT 860Illegal character in prototype for main::fòò : $\0 at (eval 1) line 1. 861######## 862# op.c 863use utf8; 864use open qw( :utf8 :std ); 865use warnings; 866eval "sub foo (\0) {}"; 867EXPECT 868Illegal character in prototype for main::foo : \0 at (eval 1) line 1. 869######## 870# op.c 871use utf8; 872use open qw( :utf8 :std ); 873use warnings; 874BEGIN { $::{"foo"} = "\$\0L\351on" } 875BEGIN { eval "sub foo (\$\0L\x{c3}\x{a9}on) {}"; } 876EXPECT 877Illegal character in prototype for main::foo : $\x{0}L... at (eval 1) line 1. 878######## 879# op.c 880use utf8; 881use open qw( :utf8 :std ); 882use warnings; 883BEGIN { eval "sub foo (\0) {}"; } 884EXPECT 885Illegal character in prototype for main::foo : \0 at (eval 1) line 1. 886######## 887# op.c 888use warnings; 889eval "sub foo (\xAB) {}"; 890EXPECT 891Illegal character in prototype for main::foo : \x{ab} at (eval 1) line 1. 892######## 893# op.c 894use utf8; 895use open qw( :utf8 :std ); 896use warnings; 897BEGIN { eval "sub foo (\x{30cb}) {}"; } 898EXPECT 899Illegal character in prototype for main::foo : \x{30cb} at (eval 1) line 1. 900######## 901# op.c 902use utf8; 903use open qw( :utf8 :std ); 904use warnings; 905BEGIN { $::{"foo"} = "\x{30cb}" } 906BEGIN { eval "sub foo {}"; } 907EXPECT 908Prototype mismatch: sub main::foo (ニ) vs none at (eval 1) line 1. 909######## 910# op.c 911$^W = 0 ; 912sub fred() ; 913sub fred($) {} 914{ 915 no warnings 'prototype' ; 916 sub Fred() ; 917 sub Fred($) {} 918 use warnings 'prototype' ; 919 sub freD() ; 920 sub freD($) {} 921} 922sub FRED() ; 923sub FRED($) {} 924EXPECT 925Prototype mismatch: sub main::fred () vs ($) at - line 4. 926Prototype mismatch: sub main::freD () vs ($) at - line 11. 927Prototype mismatch: sub main::FRED () vs ($) at - line 14. 928######## 929# op.c [Perl_ck_cmp] 930use warnings 'syntax' ; 931no warnings 'deprecated'; 932@a = $[ < 5; 933@a = $[ > 5; 934@a = $[ <= 5; 935@a = $[ >= 5; 936@a = 42 < $[; 937@a = 42 > $[; 938@a = 42 <= $[; 939@a = 42 >= $[; 940use integer; 941@a = $[ < 5; 942@a = $[ > 5; 943@a = $[ <= 5; 944@a = $[ >= 5; 945@a = 42 < $[; 946@a = 42 > $[; 947@a = 42 <= $[; 948@a = 42 >= $[; 949no integer; 950@a = $[ < $5; 951@a = $[ > $5; 952@a = $[ <= $5; 953@a = $[ >= $5; 954@a = $42 < $[; 955@a = $42 > $[; 956@a = $42 <= $[; 957@a = $42 >= $[; 958use integer; 959@a = $[ < $5; 960@a = $[ > $5; 961@a = $[ <= $5; 962@a = $[ >= $5; 963@a = $42 < $[; 964@a = $42 > $[; 965@a = $42 <= $[; 966@a = $42 >= $[; 967EXPECT 968$[ used in numeric lt (<) (did you mean $] ?) at - line 4. 969$[ used in numeric gt (>) (did you mean $] ?) at - line 5. 970$[ used in numeric le (<=) (did you mean $] ?) at - line 6. 971$[ used in numeric ge (>=) (did you mean $] ?) at - line 7. 972$[ used in numeric lt (<) (did you mean $] ?) at - line 8. 973$[ used in numeric gt (>) (did you mean $] ?) at - line 9. 974$[ used in numeric le (<=) (did you mean $] ?) at - line 10. 975$[ used in numeric ge (>=) (did you mean $] ?) at - line 11. 976$[ used in numeric lt (<) (did you mean $] ?) at - line 13. 977$[ used in numeric gt (>) (did you mean $] ?) at - line 14. 978$[ used in numeric le (<=) (did you mean $] ?) at - line 15. 979$[ used in numeric ge (>=) (did you mean $] ?) at - line 16. 980$[ used in numeric lt (<) (did you mean $] ?) at - line 17. 981$[ used in numeric gt (>) (did you mean $] ?) at - line 18. 982$[ used in numeric le (<=) (did you mean $] ?) at - line 19. 983$[ used in numeric ge (>=) (did you mean $] ?) at - line 20. 984######## 985# op.c [Perl_ck_length] 986use warnings 'syntax' ; 987length(@a); 988length(%b); 989length(@$c); 990length(%$d); 991length($a); 992length(my %h); 993length(my @g); 994EXPECT 995length() used on @a (did you mean "scalar(@a)"?) at - line 3. 996length() used on %b (did you mean "scalar(keys %b)"?) at - line 4. 997length() used on @array (did you mean "scalar(@array)"?) at - line 5. 998length() used on %hash (did you mean "scalar(keys %hash)"?) at - line 6. 999length() used on %h (did you mean "scalar(keys %h)"?) at - line 8. 1000length() used on @g (did you mean "scalar(@g)"?) at - line 9. 1001######## 1002# op.c 1003use warnings 'syntax' ; 1004join /---/, 'x', 'y', 'z'; 1005EXPECT 1006/---/ should probably be written as "---" at - line 3. 1007######## 1008# op.c 1009use utf8; 1010use open qw( :utf8 :std ); 1011use warnings 'syntax' ; 1012join /~~~/, 'x', 'y', 'z'; 1013EXPECT 1014/~~~/ should probably be written as "~~~" at - line 5. 1015######## 1016# op.c [Perl_peep] 1017use warnings 'prototype' ; 1018fred() ; 1019sub fred ($$) {} 1020no warnings 'prototype' ; 1021joe() ; 1022sub joe ($$) {} 1023EXPECT 1024main::fred() called too early to check prototype at - line 3. 1025######## 1026# op.c [Perl_newATTRSUB] 1027--FILE-- abc.pm 1028use warnings 'void' ; 1029BEGIN { $| = 1; print "in begin\n"; } 1030CHECK { print "in check\n"; } 1031INIT { print "in init\n"; } 1032END { print "in end\n"; } 1033print "in mainline\n"; 10341; 1035--FILE-- 1036use abc; 1037delete $INC{"abc.pm"}; 1038require abc; 1039do "abc.pm"; 1040EXPECT 1041in begin 1042in mainline 1043in check 1044in init 1045in begin 1046Too late to run CHECK block at abc.pm line 3. 1047Too late to run INIT block at abc.pm line 4. 1048in mainline 1049in begin 1050Too late to run CHECK block at abc.pm line 3. 1051Too late to run INIT block at abc.pm line 4. 1052in mainline 1053in end 1054in end 1055in end 1056######## 1057# op.c [Perl_newATTRSUB] 1058--FILE-- abc.pm 1059no warnings 'void' ; 1060BEGIN { $| = 1; print "in begin\n"; } 1061CHECK { print "in check\n"; } 1062INIT { print "in init\n"; } 1063END { print "in end\n"; } 1064print "in mainline\n"; 10651; 1066--FILE-- 1067require abc; 1068do "abc.pm"; 1069EXPECT 1070in begin 1071in mainline 1072in begin 1073in mainline 1074in end 1075in end 1076######## 1077# op.c 1078my @x; 1079use warnings 'syntax' ; 1080push(@x); 1081unshift(@x); 1082no warnings 'syntax' ; 1083push(@x); 1084unshift(@x); 1085EXPECT 1086Useless use of push with no values at - line 4. 1087Useless use of unshift with no values at - line 5. 1088######## 1089# op.c 1090# 20020401 mjd@plover.com at suggestion of jfriedl@yahoo.com 1091use warnings 'regexp'; 1092split /blah/g, "blah"; 1093no warnings 'regexp'; 1094split /blah/g, "blah"; 1095EXPECT 1096Use of /g modifier is meaningless in split at - line 4. 1097######## 1098# op.c 1099use warnings 'precedence'; 1100$a = $b & $c == $d; 1101$a = $b ^ $c != $d; 1102$a = $b | $c > $d; 1103$a = $b < $c & $d; 1104$a = $b >= $c ^ $d; 1105$a = $b <= $c | $d; 1106$a = $b <=> $c & $d; 1107$a &= $b == $c; $a |= $b == $c; $a ^= $b == $c; # shouldn't warn 1108no warnings 'precedence'; 1109$a = $b & $c == $d; 1110$a = $b ^ $c != $d; 1111$a = $b | $c > $d; 1112$a = $b < $c & $d; 1113$a = $b >= $c ^ $d; 1114$a = $b <= $c | $d; 1115$a = $b <=> $c & $d; 1116EXPECT 1117Possible precedence problem on bitwise & operator at - line 3. 1118Possible precedence problem on bitwise ^ operator at - line 4. 1119Possible precedence problem on bitwise | operator at - line 5. 1120Possible precedence problem on bitwise & operator at - line 6. 1121Possible precedence problem on bitwise ^ operator at - line 7. 1122Possible precedence problem on bitwise | operator at - line 8. 1123Possible precedence problem on bitwise & operator at - line 9. 1124######## 1125# op.c 1126use integer; 1127use warnings 'precedence'; 1128$a = $b & $c == $d; 1129$a = $b ^ $c != $d; 1130$a = $b | $c > $d; 1131$a = $b < $c & $d; 1132$a = $b >= $c ^ $d; 1133$a = $b <= $c | $d; 1134$a = $b <=> $c & $d; 1135no warnings 'precedence'; 1136$a = $b & $c == $d; 1137$a = $b ^ $c != $d; 1138$a = $b | $c > $d; 1139$a = $b < $c & $d; 1140$a = $b >= $c ^ $d; 1141$a = $b <= $c | $d; 1142$a = $b <=> $c & $d; 1143EXPECT 1144Possible precedence problem on bitwise & operator at - line 4. 1145Possible precedence problem on bitwise ^ operator at - line 5. 1146Possible precedence problem on bitwise | operator at - line 6. 1147Possible precedence problem on bitwise & operator at - line 7. 1148Possible precedence problem on bitwise ^ operator at - line 8. 1149Possible precedence problem on bitwise | operator at - line 9. 1150Possible precedence problem on bitwise & operator at - line 10. 1151######## 1152# op.c 1153 1154# ok => local() has desired effect; 1155# ignore=> local() silently ignored 1156 1157use warnings 'syntax'; 1158 1159local(undef); # OP_UNDEF ignore 1160sub lval : lvalue {}; 1161local(lval()); # OP_ENTERSUB 1162local($x **= 1); # OP_POW 1163local($x *= 1); # OP_MULTIPLY 1164local($x /= 1); # OP_DIVIDE 1165local($x %= 1); # OP_MODULO 1166local($x x= 1); # OP_REPEAT 1167local($x += 1); # OP_ADD 1168local($x -= 1); # OP_SUBTRACT 1169local($x .= 1); # OP_CONCAT 1170local($x <<= 1); # OP_LEFT_SHIFT 1171local($x >>= 1); # OP_RIGHT_SHIFT 1172local($x &= 1); # OP_BIT_AND 1173local($x ^= 1); # OP_BIT_XOR 1174local($x |= 1); # OP_BIT_OR 1175{ 1176 use integer; 1177 local($x *= 1); # OP_I_MULTIPLY 1178 local($x /= 1); # OP_I_DIVIDE 1179 local($x %= 1); # OP_I_MODULO 1180 local($x += 1); # OP_I_ADD 1181 local($x -= 1); # OP_I_SUBTRACT 1182} 1183local($x?$y:$z) = 1; # OP_COND_EXPR ok 1184# these two are fatal run-time errors instead 1185#local(@$a); # OP_RV2AV ok 1186#local(%$a); # OP_RV2HV ok 1187local(*a); # OP_RV2GV ok 1188local(@a[1,2]); # OP_ASLICE ok 1189local(@a{1,2}); # OP_HSLICE ok 1190local(@a = (1,2)); # OP_AASSIGN 1191local($$x); # OP_RV2SV ok 1192local($#a); # OP_AV2ARYLEN 1193local($x = 1); # OP_SASSIGN 1194local($x &&= 1); # OP_ANDASSIGN 1195local($x ||= 1); # OP_ORASSIGN 1196local($x //= 1); # OP_DORASSIGN 1197local($a[0]); # OP_AELEMFAST ok 1198 1199local(substr($x,0,1)); # OP_SUBSTR 1200local(pos($x)); # OP_POS 1201local(vec($x,0,1)); # OP_VEC 1202local($a[$b]); # OP_AELEM ok 1203local($a{$b}); # OP_HELEM ok 1204 1205no warnings 'syntax'; 1206EXPECT 1207Useless localization of subroutine entry at - line 10. 1208Useless localization of exponentiation (**) at - line 11. 1209Useless localization of multiplication (*) at - line 12. 1210Useless localization of division (/) at - line 13. 1211Useless localization of modulus (%) at - line 14. 1212Useless localization of repeat (x) at - line 15. 1213Useless localization of addition (+) at - line 16. 1214Useless localization of subtraction (-) at - line 17. 1215Useless localization of concatenation (.) or string at - line 18. 1216Useless localization of left bitshift (<<) at - line 19. 1217Useless localization of right bitshift (>>) at - line 20. 1218Useless localization of bitwise and (&) at - line 21. 1219Useless localization of bitwise xor (^) at - line 22. 1220Useless localization of bitwise or (|) at - line 23. 1221Useless localization of integer multiplication (*) at - line 26. 1222Useless localization of integer division (/) at - line 27. 1223Useless localization of integer modulus (%) at - line 28. 1224Useless localization of integer addition (+) at - line 29. 1225Useless localization of integer subtraction (-) at - line 30. 1226Useless localization of list assignment at - line 39. 1227Useless localization of array length at - line 41. 1228Useless localization of scalar assignment at - line 42. 1229Useless localization of logical and assignment (&&=) at - line 43. 1230Useless localization of logical or assignment (||=) at - line 44. 1231Useless localization of defined or assignment (//=) at - line 45. 1232Useless localization of substr at - line 48. 1233Useless localization of match position at - line 49. 1234Useless localization of vec at - line 50. 1235######## 1236# op.c 1237my $x1 if 0; 1238my @x2 if 0; 1239my %x3 if 0; 1240my ($x4) if 0; 1241my ($x5,@x6, %x7) if 0; 12420 && my $z1; 12430 && my (%z2); 1244# these shouldn't warn 1245our $x if 0; 1246our $x unless 0; 1247if (0) { my $w1 } 1248if (my $w2) { $a=1 } 1249if ($a && (my $w3 = 1)) {$a = 2} 1250 1251EXPECT 1252Deprecated use of my() in false conditional at - line 2. 1253Deprecated use of my() in false conditional at - line 3. 1254Deprecated use of my() in false conditional at - line 4. 1255Deprecated use of my() in false conditional at - line 5. 1256Deprecated use of my() in false conditional at - line 6. 1257Deprecated use of my() in false conditional at - line 7. 1258Deprecated use of my() in false conditional at - line 8. 1259######## 1260# op.c 1261$[ = 1; 1262($[) = 1; 1263use warnings 'deprecated'; 1264$[ = 2; 1265($[) = 2; 1266no warnings 'deprecated'; 1267$[ = 3; 1268($[) = 3; 1269EXPECT 1270Use of assignment to $[ is deprecated at - line 2. 1271Use of assignment to $[ is deprecated at - line 3. 1272Use of assignment to $[ is deprecated at - line 5. 1273Use of assignment to $[ is deprecated at - line 6. 1274######## 1275# op.c 1276use warnings 'void'; 1277@x = split /y/, "z"; 1278$x = split /y/, "z"; 1279 split /y/, "z"; 1280no warnings 'void'; 1281@x = split /y/, "z"; 1282$x = split /y/, "z"; 1283 split /y/, "z"; 1284EXPECT 1285Useless use of split in void context at - line 5. 1286######## 1287# op.c 1288use warnings 'redefine' ; 1289use utf8; 1290use open qw( :utf8 :std ); 1291sub frèd {} 1292sub frèd {} 1293no warnings 'redefine' ; 1294sub frèd {} 1295EXPECT 1296Subroutine frèd redefined at - line 6. 1297######## 1298# op.c 1299use warnings 'redefine' ; 1300use utf8; 1301use open qw( :utf8 :std ); 1302sub frèd () { 1 } 1303sub frèd () { 1 } 1304no warnings 'redefine' ; 1305sub frèd () { 1 } 1306EXPECT 1307Constant subroutine frèd redefined at - line 6. 1308######## 1309# op.c 1310use utf8; 1311use open qw( :utf8 :std ); 1312sub frèd () { 1 } 1313sub frèd () { 2 } 1314EXPECT 1315Constant subroutine frèd redefined at - line 5. 1316######## 1317# op.c 1318use utf8; 1319use open qw( :utf8 :std ); 1320sub frèd () { 1 } 1321*frèd = sub () { 2 }; 1322EXPECT 1323Constant subroutine main::frèd redefined at - line 5. 1324######## 1325# op.c 1326use warnings 'redefine' ; 1327use utf8; 1328use open qw( :utf8 :std ); 1329sub ᚠርƊ {} 1330sub ᚠርƊ {} 1331no warnings 'redefine' ; 1332sub ᚠርƊ {} 1333EXPECT 1334Subroutine ᚠርƊ redefined at - line 6. 1335######## 1336# op.c 1337use warnings 'redefine' ; 1338use utf8; 1339use open qw( :utf8 :std ); 1340sub ᚠርƊ () { 1 } 1341sub ᚠርƊ () { 1 } 1342no warnings 'redefine' ; 1343sub ᚠርƊ () { 1 } 1344EXPECT 1345Constant subroutine ᚠርƊ redefined at - line 6. 1346######## 1347# op.c 1348use utf8; 1349use open qw( :utf8 :std ); 1350sub ᚠርƊ () { 1 } 1351sub ᚠርƊ () { 2 } 1352EXPECT 1353Constant subroutine ᚠርƊ redefined at - line 5. 1354######## 1355# op.c 1356use utf8; 1357use open qw( :utf8 :std ); 1358sub ᚠርƊ () { 1 } 1359*ᚠርƊ = sub () { 2 }; 1360EXPECT 1361Constant subroutine main::ᚠርƊ redefined at - line 5. 1362######## 1363