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