1 op.c AOK 2 3 Use of my $_ is experimental 4 my $_ ; 5 6 Found = in conditional, should be == 7 1 if $a = 1 ; 8 9 Scalar value %.*s better written as $%.*s" 10 @a[3] = 2; 11 @a{3} = 2; 12 13 Useless use of time in void context 14 Useless use of a variable in void context 15 Useless use of a constant in void context 16 time ; 17 $a ; 18 "abc" 19 20 Useless use of sort in scalar context 21 my $x = sort (2,1,3); 22 23 Applying %s to %s will act on scalar(%s) 24 my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; 25 @a =~ /abc/ ; 26 @a =~ s/a/b/ ; 27 @a =~ tr/a/b/ ; 28 @$b =~ /abc/ ; 29 @$b =~ s/a/b/ ; 30 @$b =~ tr/a/b/ ; 31 %a =~ /abc/ ; 32 %a =~ s/a/b/ ; 33 %a =~ tr/a/b/ ; 34 %$c =~ /abc/ ; 35 %$c =~ s/a/b/ ; 36 %$c =~ tr/a/b/ ; 37 38 39 Parentheses missing around "my" list at -e line 1. 40 my $a, $b = (1,2); 41 42 Parentheses missing around "local" list at -e line 1. 43 local $a, $b = (1,2); 44 45 Bareword found in conditional at -e line 1. 46 use warnings 'bareword'; my $x = print(ABC || 1); 47 48 Value of %s may be \"0\"; use \"defined\" 49 $x = 1 if $x = <FH> ; 50 $x = 1 while $x = <FH> ; 51 52 Subroutine fred redefined at -e line 1. 53 sub fred{1;} sub fred{1;} 54 55 Constant subroutine %s redefined 56 sub fred() {1;} sub fred() {1;} 57 58 Format FRED redefined at /tmp/x line 5. 59 format FRED = 60 . 61 format FRED = 62 . 63 64 Array @%s missing the @ in argument %d of %s() 65 push fred ; 66 67 push on reference is experimental [ck_fun] 68 pop on reference is experimental 69 shift on reference is experimental 70 unshift on reference is experimental 71 splice on reference is experimental 72 73 Hash %%%s missing the %% in argument %d of %s() 74 keys joe ; 75 76 Statement unlikely to be reached 77 (Maybe you meant system() when you said exec()? 78 exec "true" ; my $a 79 80 defined(@array) is deprecated 81 (Maybe you should just omit the defined()?) 82 my @a ; defined @a ; 83 defined (@a = (1,2,3)) ; 84 85 defined(%hash) is deprecated 86 (Maybe you should just omit the defined()?) 87 my %h ; defined %h ; 88 89 "my %s" used in sort comparison 90 91 $[ used in comparison (did you mean $] ?) 92 93 each on reference is experimental [ck_each] 94 keys on reference is experimental 95 values on reference is experimental 96 97 length() used on @array (did you mean "scalar(@array)"?) 98 length() used on %hash (did you mean "scalar(keys %hash)"?) 99 100 /---/ should probably be written as "---" 101 join(/---/, @foo); 102 103 %s() called too early to check prototype [Perl_peep] 104 fred() ; sub fred ($$) {} 105 106 107 Package '%s' not found (did you use the incorrect case?) 108 109 Use of /g modifier is meaningless in split 110 111 Possible precedence problem on bitwise %c operator [Perl_ck_bitop] 112 113 Mandatory Warnings 114 ------------------ 115 Prototype mismatch: [cv_ckproto] 116 sub fred() ; 117 sub fred($) {} 118 119 oops: oopsAV [oopsAV] TODO 120 oops: oopsHV [oopsHV] TODO 121 122__END__ 123# op.c 124use warnings 'experimental::lexical_topic' ; 125my $_; 126CORE::state $_; 127no warnings 'experimental::lexical_topic' ; 128my $_; 129CORE::state $_; 130EXPECT 131Use of my $_ is experimental at - line 3. 132Use of state $_ is experimental at - line 4. 133######## 134# op.c 135use warnings 'syntax' ; 1361 if $a = 1 ; 1371 if $a 138 = 1 ; 139no warnings 'syntax' ; 1401 if $a = 1 ; 1411 if $a 142 = 1 ; 143EXPECT 144Found = in conditional, should be == at - line 3. 145Found = in conditional, should be == at - line 4. 146######## 147# op.c 148use warnings 'syntax' ; 149use constant foo => 1; 1501 if $a = foo ; 151no warnings 'syntax' ; 1521 if $a = foo ; 153EXPECT 154######## 155# op.c 156use warnings 'syntax' ; 157@a[3]; 158@a{3}; 159@a["]"]; 160@a{"]"}; 161@a["}"]; 162@a{"}"}; 163@a{$_}; 164@a{--$_}; 165@a[$_]; 166@a[--$_]; 167no warnings 'syntax' ; 168@a[3]; 169@a{3}; 170EXPECT 171Scalar value @a[3] better written as $a[3] at - line 3. 172Scalar value @a{3} better written as $a{3} at - line 4. 173Scalar value @a["]"] better written as $a["]"] at - line 5. 174Scalar value @a{"]"} better written as $a{"]"} at - line 6. 175Scalar value @a["}"] better written as $a["}"] at - line 7. 176Scalar value @a{"}"} better written as $a{"}"} at - line 8. 177Scalar value @a{...} better written as $a{...} at - line 9. 178Scalar value @a{...} better written as $a{...} at - line 10. 179Scalar value @a[...] better written as $a[...] at - line 11. 180Scalar value @a[...] better written as $a[...] at - line 12. 181######## 182# op.c 183use utf8; 184use open qw( :utf8 :std ); 185use warnings 'syntax' ; 186@à[3]; 187@à{3}; 188no warnings 'syntax' ; 189@à[3]; 190@à{3}; 191EXPECT 192Scalar value @à[3] better written as $à[3] at - line 5. 193Scalar value @à{3} better written as $à{3} at - line 6. 194######## 195# op.c 196use utf8; 197use open qw( :utf8 :std ); 198use warnings 'syntax' ; 199@ぁ[3]; 200@ぁ{3}; 201no warnings 'syntax' ; 202@ぁ[3]; 203@ぁ{3}; 204EXPECT 205Scalar value @ぁ[3] better written as $ぁ[3] at - line 5. 206Scalar value @ぁ{3} better written as $ぁ{3} at - line 6. 207######## 208# op.c 209# "Scalar value better written as" false positives 210# [perl #28380] and [perl #114024] 211use warnings 'syntax'; 212 213# hashes 214@h{qw"a b c"} = 1..3; 215@h{qw'a b c'} = 1..3; 216@h{qw$a b c$} = 1..3; 217@h{qw-a b c-} = 1..3; 218@h{qw#a b c#} = 1..3; 219@h{ qw#a b c#} = 1..3; 220@h{ qw#a b c#} = 1..3; # tab before qw 221@h{qw "a"}; 222@h{ qw "a"}; 223@h{ qw "a"}; 224sub foo() { qw/abc def ghi/ } 225@X{+foo} = ( 1 .. 3 ); 226$_ = "abc"; @X{split ""} = ( 1 .. 3 ); 227my @s = @f{"}", "a"}; 228my @s = @f{"]", "a"}; 229@a{$],0}; 230@_{0} = /(.*)/; 231@h{m "$re"}; 232@h{qx ""} if 0; 233@h{glob ""}; 234@h{readline ""}; 235@h{m ""}; 236use constant phoo => 1..3; 237@h{+phoo}; # rv2av 238{ 239 no warnings 'deprecated'; 240 @h{each H}; 241 @h{values H}; 242 @h{keys H}; 243} 244@h{sort foo}; 245@h{reverse foo}; 246@h{caller 0}; 247@h{lstat ""}; 248@h{stat ""}; 249@h{readdir ""}; 250@h{system ""} if 0; 251@h{+times} if 0; 252@h{localtime 0}; 253@h{gmtime 0}; 254@h{eval ""}; 255{ 256 no warnings 'experimental::autoderef'; 257 @h{each $foo} if 0; 258 @h{keys $foo} if 0; 259 @h{values $foo} if 0; 260} 261 262# arrays 263@h[qw"a b c"] = 1..3; 264@h[qw'a b c'] = 1..3; 265@h[qw$a b c$] = 1..3; 266@h[qw-a b c-] = 1..3; 267@h[qw#a b c#] = 1..3; 268@h[ qw#a b c#] = 1..3; 269@h[ qw#a b c#] = 1..3; # tab before qw 270@h[qw "a"]; 271@h[ qw "a"]; 272@h[ qw "a"]; 273sub foo() { qw/abc def ghi/ } 274@X[+foo] = ( 1 .. 3 ); 275$_ = "abc"; @X[split ""] = ( 1 .. 3 ); 276my @s = @f["}", "a"]; 277my @s = @f["]", "a"]; 278@a[$],0]; 279@_[0] = /(.*)/; 280@h[m "$re"]; 281@h[qx ""] if 0; 282@h[glob ""]; 283@h[readline ""]; 284@h[m ""]; 285use constant phoo => 1..3; 286@h[+phoo]; # rv2av 287{ 288 no warnings 'deprecated'; 289 @h[each H]; 290 @h[values H]; 291 @h[keys H]; 292} 293@h[sort foo]; 294@h[reverse foo]; 295@h[caller 0]; 296@h[lstat ""]; 297@h[stat ""]; 298@h[readdir ""]; 299@h[system ""] if 0; 300@h[+times] if 0; 301@h[localtime 0]; 302@h[gmtime 0]; 303@h[eval ""]; 304{ 305 no warnings 'experimental::autoderef'; 306 @h[each $foo] if 0; 307 @h[keys $foo] if 0; 308 @h[values $foo] if 0; 309} 310EXPECT 311######## 312# op.c 313# "Scalar value better written as" should not trigger for syntax errors 314use warnings 'syntax'; 315@a[] 316EXPECT 317syntax error at - line 4, near "[]" 318Execution of - aborted due to compilation errors. 319######## 320# op.c 321my (@foo, %foo); 322%main::foo->{"bar"}; 323%foo->{"bar"}; 324@main::foo->[23]; 325@foo->[23]; 326$main::foo = {}; %$main::foo->{"bar"}; 327$foo = {}; %$foo->{"bar"}; 328$main::foo = []; @$main::foo->[34]; 329$foo = []; @$foo->[34]; 330no warnings 'deprecated'; 331%main::foo->{"bar"}; 332%foo->{"bar"}; 333@main::foo->[23]; 334@foo->[23]; 335$main::foo = {}; %$main::foo->{"bar"}; 336$foo = {}; %$foo->{"bar"}; 337$main::foo = []; @$main::foo->[34]; 338$foo = []; @$foo->[34]; 339EXPECT 340Using a hash as a reference is deprecated at - line 3. 341Using a hash as a reference is deprecated at - line 4. 342Using an array as a reference is deprecated at - line 5. 343Using an array as a reference is deprecated at - line 6. 344Using a hash as a reference is deprecated at - line 7. 345Using a hash as a reference is deprecated at - line 8. 346Using an array as a reference is deprecated at - line 9. 347Using an array as a reference is deprecated at - line 10. 348######## 349# op.c 350use warnings 'void' ; no warnings 'experimental::smartmatch'; close STDIN ; 351#line 2 3521 x 3 ; # OP_REPEAT (folded) 353(1) x 3 ; # OP_REPEAT 354 # OP_GVSV 355wantarray ; # OP_WANTARRAY 356 # OP_GV 357 # OP_PADSV 358 # OP_PADAV 359 # OP_PADHV 360 # OP_PADANY 361 # OP_AV2ARYLEN 362ref ; # OP_REF 363\@a ; # OP_REFGEN 364\$a ; # OP_SREFGEN 365defined $a ; # OP_DEFINED 366hex $a ; # OP_HEX 367oct $a ; # OP_OCT 368length $a ; # OP_LENGTH 369substr $a,1 ; # OP_SUBSTR 370vec $a,1,2 ; # OP_VEC 371index $a,1,2 ; # OP_INDEX 372rindex $a,1,2 ; # OP_RINDEX 373sprintf $a ; # OP_SPRINTF 374$a[0] ; # OP_AELEM 375 # OP_AELEMFAST 376@a[0] ; # OP_ASLICE 377#values %a ; # OP_VALUES 378#keys %a ; # OP_KEYS 379$a{0} ; # OP_HELEM 380@a{0} ; # OP_HSLICE 381unpack "a", "a" ; # OP_UNPACK 382pack $a,"" ; # OP_PACK 383join "" ; # OP_JOIN 384(@a)[0,1] ; # OP_LSLICE 385 # OP_ANONLIST 386 # OP_ANONHASH 387sort(1,2) ; # OP_SORT 388reverse(1,2) ; # OP_REVERSE 389 # OP_RANGE 390 # OP_FLIP 391(1 ..2) ; # OP_FLOP 392caller ; # OP_CALLER 393fileno STDIN ; # OP_FILENO 394eof STDIN ; # OP_EOF 395tell STDIN ; # OP_TELL 396readlink 1; # OP_READLINK 397time ; # OP_TIME 398localtime ; # OP_LOCALTIME 399gmtime ; # OP_GMTIME 400eval { getgrnam 1 }; # OP_GGRNAM 401eval { getgrgid 1 }; # OP_GGRGID 402eval { getpwnam 1 }; # OP_GPWNAM 403eval { getpwuid 1 }; # OP_GPWUID 404prototype "foo"; # OP_PROTOTYPE 405$a ~~ $b; # OP_SMARTMATCH 406$a <=> $b; # OP_NCMP 407"dsatrewq"; 408"diatrewq"; 409"igatrewq"; 410use 5.015; 411__SUB__ # OP_RUNCV 412EXPECT 413Useless use of a constant ("111") in void context at - line 2. 414Useless use of repeat (x) in void context at - line 3. 415Useless use of wantarray in void context at - line 5. 416Useless use of reference-type operator in void context at - line 12. 417Useless use of reference constructor in void context at - line 13. 418Useless use of single ref constructor in void context at - line 14. 419Useless use of defined operator in void context at - line 15. 420Useless use of hex in void context at - line 16. 421Useless use of oct in void context at - line 17. 422Useless use of length in void context at - line 18. 423Useless use of substr in void context at - line 19. 424Useless use of vec in void context at - line 20. 425Useless use of index in void context at - line 21. 426Useless use of rindex in void context at - line 22. 427Useless use of sprintf in void context at - line 23. 428Useless use of array element in void context at - line 24. 429Useless use of array slice in void context at - line 26. 430Useless use of hash element in void context at - line 29. 431Useless use of hash slice in void context at - line 30. 432Useless use of unpack in void context at - line 31. 433Useless use of pack in void context at - line 32. 434Useless use of join or string in void context at - line 33. 435Useless use of list slice in void context at - line 34. 436Useless use of sort in void context at - line 37. 437Useless use of reverse in void context at - line 38. 438Useless use of range (or flop) in void context at - line 41. 439Useless use of caller in void context at - line 42. 440Useless use of fileno in void context at - line 43. 441Useless use of eof in void context at - line 44. 442Useless use of tell in void context at - line 45. 443Useless use of readlink in void context at - line 46. 444Useless use of time in void context at - line 47. 445Useless use of localtime in void context at - line 48. 446Useless use of gmtime in void context at - line 49. 447Useless use of getgrnam in void context at - line 50. 448Useless use of getgrgid in void context at - line 51. 449Useless use of getpwnam in void context at - line 52. 450Useless use of getpwuid in void context at - line 53. 451Useless use of subroutine prototype in void context at - line 54. 452Useless use of smart match in void context at - line 55. 453Useless use of numeric comparison (<=>) in void context at - line 56. 454Useless use of a constant ("dsatrewq") in void context at - line 57. 455Useless use of a constant ("diatrewq") in void context at - line 58. 456Useless use of a constant ("igatrewq") in void context at - line 59. 457Useless use of __SUB__ in void context at - line 61. 458######## 459# op.c 460use warnings 'void' ; close STDIN ; 461my $x = sort (2,1,3); 462no warnings 'void' ; 463$x = sort (2,1,3); 464EXPECT 465Useless use of sort in scalar context at - line 3. 466######## 467# op.c 468no warnings 'void' ; close STDIN ; 4691 x 3 ; # OP_REPEAT 470 # OP_GVSV 471wantarray ; # OP_WANTARRAY 472 # OP_GV 473 # OP_PADSV 474 # OP_PADAV 475 # OP_PADHV 476 # OP_PADANY 477 # OP_AV2ARYLEN 478ref ; # OP_REF 479\@a ; # OP_REFGEN 480\$a ; # OP_SREFGEN 481defined $a ; # OP_DEFINED 482hex $a ; # OP_HEX 483oct $a ; # OP_OCT 484length $a ; # OP_LENGTH 485substr $a,1 ; # OP_SUBSTR 486vec $a,1,2 ; # OP_VEC 487index $a,1,2 ; # OP_INDEX 488rindex $a,1,2 ; # OP_RINDEX 489sprintf $a ; # OP_SPRINTF 490$a[0] ; # OP_AELEM 491 # OP_AELEMFAST 492@a[0] ; # OP_ASLICE 493#values %a ; # OP_VALUES 494#keys %a ; # OP_KEYS 495$a{0} ; # OP_HELEM 496@a{0} ; # OP_HSLICE 497unpack "a", "a" ; # OP_UNPACK 498pack $a,"" ; # OP_PACK 499join "" ; # OP_JOIN 500(@a)[0,1] ; # OP_LSLICE 501 # OP_ANONLIST 502 # OP_ANONHASH 503sort(1,2) ; # OP_SORT 504reverse(1,2) ; # OP_REVERSE 505 # OP_RANGE 506 # OP_FLIP 507(1 ..2) ; # OP_FLOP 508caller ; # OP_CALLER 509fileno STDIN ; # OP_FILENO 510eof STDIN ; # OP_EOF 511tell STDIN ; # OP_TELL 512readlink 1; # OP_READLINK 513time ; # OP_TIME 514localtime ; # OP_LOCALTIME 515gmtime ; # OP_GMTIME 516eval { getgrnam 1 }; # OP_GGRNAM 517eval { getgrgid 1 }; # OP_GGRGID 518eval { getpwnam 1 }; # OP_GPWNAM 519eval { getpwuid 1 }; # OP_GPWUID 520prototype "foo"; # OP_PROTOTYPE 521EXPECT 522######## 523# op.c 524use warnings 'void' ; 525for (@{[0]}) { "$_" } # check warning isn't duplicated 526no warnings 'void' ; 527for (@{[0]}) { "$_" } # check warning isn't duplicated 528EXPECT 529Useless use of string in void context at - line 3. 530######## 531# op.c 532use warnings 'void' ; 533use Config ; 534BEGIN { 535 if ( ! $Config{d_telldir}) { 536 print <<EOM ; 537SKIPPED 538# telldir not present 539EOM 540 exit 541 } 542} 543telldir 1 ; # OP_TELLDIR 544no warnings 'void' ; 545telldir 1 ; # OP_TELLDIR 546EXPECT 547Useless use of telldir in void context at - line 13. 548######## 549# op.c 550use warnings 'void' ; 551use Config ; 552BEGIN { 553 if ( ! $Config{d_getppid}) { 554 print <<EOM ; 555SKIPPED 556# getppid not present 557EOM 558 exit 559 } 560} 561getppid ; # OP_GETPPID 562no warnings 'void' ; 563getppid ; # OP_GETPPID 564EXPECT 565Useless use of getppid in void context at - line 13. 566######## 567# op.c 568use warnings 'void' ; 569use Config ; 570BEGIN { 571 if ( ! $Config{d_getpgrp}) { 572 print <<EOM ; 573SKIPPED 574# getpgrp not present 575EOM 576 exit 577 } 578} 579getpgrp ; # OP_GETPGRP 580no warnings 'void' ; 581getpgrp ; # OP_GETPGRP 582EXPECT 583Useless use of getpgrp in void context at - line 13. 584######## 585# op.c 586use warnings 'void' ; 587use Config ; 588BEGIN { 589 if ( ! $Config{d_times}) { 590 print <<EOM ; 591SKIPPED 592# times not present 593EOM 594 exit 595 } 596} 597times ; # OP_TMS 598no warnings 'void' ; 599times ; # OP_TMS 600EXPECT 601Useless use of times in void context at - line 13. 602######## 603# op.c 604use warnings 'void' ; 605use Config ; 606BEGIN { 607 if ( ! $Config{d_getprior} or $^O eq 'os2') { # Locks before fixpak22 608 print <<EOM ; 609SKIPPED 610# getpriority not present 611EOM 612 exit 613 } 614} 615getpriority 1,2; # OP_GETPRIORITY 616no warnings 'void' ; 617getpriority 1,2; # OP_GETPRIORITY 618EXPECT 619Useless use of getpriority in void context at - line 13. 620######## 621# op.c 622use warnings 'void' ; 623use Config ; 624BEGIN { 625 if ( ! $Config{d_getlogin}) { 626 print <<EOM ; 627SKIPPED 628# getlogin not present 629EOM 630 exit 631 } 632} 633getlogin ; # OP_GETLOGIN 634no warnings 'void' ; 635getlogin ; # OP_GETLOGIN 636EXPECT 637Useless use of getlogin in void context at - line 13. 638######## 639# op.c 640use warnings 'void' ; 641use Config ; BEGIN { 642if ( ! $Config{d_socket}) { 643 print <<EOM ; 644SKIPPED 645# getsockname not present 646# getpeername not present 647# gethostbyname not present 648# gethostbyaddr not present 649# gethostent not present 650# getnetbyname not present 651# getnetbyaddr not present 652# getnetent not present 653# getprotobyname not present 654# getprotobynumber not present 655# getprotoent not present 656# getservbyname not present 657# getservbyport not present 658# getservent not present 659EOM 660 exit 661} } 662getsockname STDIN ; # OP_GETSOCKNAME 663getpeername STDIN ; # OP_GETPEERNAME 664gethostbyname 1 ; # OP_GHBYNAME 665gethostbyaddr 1,2; # OP_GHBYADDR 666gethostent ; # OP_GHOSTENT 667getnetbyname 1 ; # OP_GNBYNAME 668getnetbyaddr 1,2 ; # OP_GNBYADDR 669getnetent ; # OP_GNETENT 670getprotobyname 1; # OP_GPBYNAME 671getprotobynumber 1; # OP_GPBYNUMBER 672getprotoent ; # OP_GPROTOENT 673getservbyname 1,2; # OP_GSBYNAME 674getservbyport 1,2; # OP_GSBYPORT 675getservent ; # OP_GSERVENT 676 677no warnings 'void' ; 678getsockname STDIN ; # OP_GETSOCKNAME 679getpeername STDIN ; # OP_GETPEERNAME 680gethostbyname 1 ; # OP_GHBYNAME 681gethostbyaddr 1,2; # OP_GHBYADDR 682gethostent ; # OP_GHOSTENT 683getnetbyname 1 ; # OP_GNBYNAME 684getnetbyaddr 1,2 ; # OP_GNBYADDR 685getnetent ; # OP_GNETENT 686getprotobyname 1; # OP_GPBYNAME 687getprotobynumber 1; # OP_GPBYNUMBER 688getprotoent ; # OP_GPROTOENT 689getservbyname 1,2; # OP_GSBYNAME 690getservbyport 1,2; # OP_GSBYPORT 691getservent ; # OP_GSERVENT 692INIT { 693 # some functions may not be there, so we exit without running 694 exit; 695} 696EXPECT 697Useless use of getsockname in void context at - line 24. 698Useless use of getpeername in void context at - line 25. 699Useless use of gethostbyname in void context at - line 26. 700Useless use of gethostbyaddr in void context at - line 27. 701Useless use of gethostent in void context at - line 28. 702Useless use of getnetbyname in void context at - line 29. 703Useless use of getnetbyaddr in void context at - line 30. 704Useless use of getnetent in void context at - line 31. 705Useless use of getprotobyname in void context at - line 32. 706Useless use of getprotobynumber in void context at - line 33. 707Useless use of getprotoent in void context at - line 34. 708Useless use of getservbyname in void context at - line 35. 709Useless use of getservbyport in void context at - line 36. 710Useless use of getservent in void context at - line 37. 711######## 712# op.c 713use warnings 'void' ; 714*a ; # OP_RV2GV 715$a ; # OP_RV2SV 716@a ; # OP_RV2AV 717%a ; # OP_RV2HV 718no warnings 'void' ; 719*a ; # OP_RV2GV 720$a ; # OP_RV2SV 721@a ; # OP_RV2AV 722%a ; # OP_RV2HV 723EXPECT 724Useless use of a variable in void context at - line 3. 725Useless use of a variable in void context at - line 4. 726Useless use of a variable in void context at - line 5. 727Useless use of a variable in void context at - line 6. 728######## 729# op.c 730use warnings 'void' ; 731"abc"; # OP_CONST 7327 ; # OP_CONST 733"x" . "y"; # optimized to OP_CONST 7342 + 2; # optimized to OP_CONST 735use constant U => undef; 736U; 737qq/" \n/; 7385 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT 739print "boo\n" if U; # test OPpCONST_SHORTCIRCUIT 740if($foo){}elsif(""){} # test OPpCONST_SHORTCIRCUIT 741no warnings 'void' ; 742"abc"; # OP_CONST 7437 ; # OP_CONST 744"x" . "y"; # optimized to OP_CONST 7452 + 2; # optimized to OP_CONST 746EXPECT 747Useless use of a constant ("abc") in void context at - line 3. 748Useless use of a constant (7) in void context at - line 4. 749Useless use of a constant ("xy") in void context at - line 5. 750Useless use of a constant (4) in void context at - line 6. 751Useless use of a constant (undef) in void context at - line 8. 752Useless use of a constant ("\"\t\n") in void context at - line 9. 753######## 754# op.c 755use utf8; 756use open qw( :utf8 :std ); 757use warnings 'void' ; 758"àḆc"; # OP_CONST 759"Ẋ" . "ƴ"; # optimized to OP_CONST 760FOO; # Bareword optimized to OP_CONST 761use constant ů => undef; 762ů; 7635 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT 764print "boo\n" if ů; # test OPpCONST_SHORTCIRCUIT 765no warnings 'void' ; 766"àḆc"; # OP_CONST 767"Ẋ" . "ƴ"; # optimized to OP_CONST 768EXPECT 769Useless use of a constant ("\340\x{1e06}c") in void context at - line 5. 770Useless use of a constant ("\x{1e8a}\x{1b4}") in void context at - line 6. 771Useless use of a constant ("\x{ff26}\x{ff2f}\x{ff2f}") in void context at - line 7. 772Useless use of a constant (undef) in void context at - line 9. 773######## 774# op.c 775# 776use warnings 'misc' ; 777my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;my $d = 'test'; 778@a =~ /abc/ ; 779@a2 =~ s/a/b/ ; 780@a3 =~ tr/a/b/ ; 781@$b =~ /abc/ ; 782@$b =~ s/a/b/ ; 783@$b =~ tr/a/b/ ; 784%a =~ /abc/ ; 785%a2 =~ s/a/b/ ; 786%a3 =~ tr/a/b/ ; 787%$c =~ /abc/ ; 788%$c =~ s/a/b/ ; 789%$c =~ tr/a/b/ ; 790$d =~ tr/a/b/d ; 791$d2 =~ tr/a/bc/; 792$d3 =~ tr//b/c; 793{ 794no warnings 'misc' ; 795my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; my $d = 'test'; 796@a =~ /abc/ ; 797@a =~ s/a/b/ ; 798@a =~ tr/a/b/ ; 799@$b =~ /abc/ ; 800@$b =~ s/a/b/ ; 801@$b =~ tr/a/b/ ; 802%a =~ /abc/ ; 803%a =~ s/a/b/ ; 804%a =~ tr/a/b/ ; 805%$c =~ /abc/ ; 806%$c =~ s/a/b/ ; 807%$c =~ tr/a/b/ ; 808$d =~ tr/a/b/d ; 809$d =~ tr/a/bc/ ; 810$d =~ tr//b/c; 811} 812EXPECT 813Applying pattern match (m//) to @a will act on scalar(@a) at - line 5. 814Applying substitution (s///) to @a2 will act on scalar(@a2) at - line 6. 815Applying transliteration (tr///) to @a3 will act on scalar(@a3) at - line 7. 816Applying pattern match (m//) to @array will act on scalar(@array) at - line 8. 817Applying substitution (s///) to @array will act on scalar(@array) at - line 9. 818Applying transliteration (tr///) to @array will act on scalar(@array) at - line 10. 819Applying pattern match (m//) to %a will act on scalar(%a) at - line 11. 820Applying substitution (s///) to %a2 will act on scalar(%a2) at - line 12. 821Applying transliteration (tr///) to %a3 will act on scalar(%a3) at - line 13. 822Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 14. 823Applying substitution (s///) to %hash will act on scalar(%hash) at - line 15. 824Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 16. 825Useless use of /d modifier in transliteration operator at - line 17. 826Replacement list is longer than search list at - line 18. 827Can't modify array dereference in substitution (s///) at - line 6, near "s/a/b/ ;" 828BEGIN not safe after errors--compilation aborted at - line 21. 829######## 830# op.c 831use warnings 'parenthesis' ; 832my $a, $b = (1,2); 833my @foo,%bar, $quux; # there's a TAB here 834my $x, $y or print; 835no warnings 'parenthesis' ; 836my $c, $d = (1,2); 837EXPECT 838Parentheses missing around "my" list at - line 3. 839Parentheses missing around "my" list at - line 4. 840######## 841# op.c 842use warnings 'parenthesis' ; 843our $a, $b = (1,2); 844no warnings 'parenthesis' ; 845our $c, $d = (1,2); 846EXPECT 847Parentheses missing around "our" list at - line 3. 848######## 849# op.c 850use warnings 'parenthesis' ; 851local $a, $b = (1,2); 852local *f, *g; 853no warnings 'parenthesis' ; 854local $c, $d = (1,2); 855EXPECT 856Parentheses missing around "local" list at - line 3. 857Parentheses missing around "local" list at - line 4. 858######## 859# op.c 860use warnings 'bareword' ; 861print (ABC || 1) ; 862no warnings 'bareword' ; 863print (ABC || 1) ; 864EXPECT 865Bareword found in conditional at - line 3. 866######## 867--FILE-- abc 868 869--FILE-- 870# op.c 871use warnings 'misc' ; 872open FH, "<abc" ; 873$x = 1 if $x = <FH> ; 874$x = 1 if $x 875 = <FH> ; 876no warnings 'misc' ; 877$x = 1 if $x = <FH> ; 878$x = 1 if $x 879 = <FH> ; 880EXPECT 881Value of <HANDLE> construct can be "0"; test with defined() at - line 4. 882Value of <HANDLE> construct can be "0"; test with defined() at - line 5. 883######## 884# op.c 885use warnings 'misc' ; 886opendir FH, "." ; 887$x = 1 if $x = readdir FH ; 888$x = 1 if $x 889 = readdir FH ; 890no warnings 'misc' ; 891$x = 1 if $x = readdir FH ; 892$x = 1 if $x 893 = readdir FH ; 894closedir FH ; 895EXPECT 896Value of readdir() operator can be "0"; test with defined() at - line 4. 897Value of readdir() operator can be "0"; test with defined() at - line 5. 898######## 899# op.c 900use warnings 'misc' ; 901$x = 1 if $x = <*> ; 902$x = 1 if $x 903 = <*> ; 904no warnings 'misc' ; 905$x = 1 if $x = <*> ; 906$x = 1 if $x 907 = <*> ; 908EXPECT 909Value of glob construct can be "0"; test with defined() at - line 3. 910Value of glob construct can be "0"; test with defined() at - line 4. 911######## 912# op.c 913use warnings 'misc' ; 914%a = (1,2,3,4) ; 915$x = 1 if $x = each %a ; 916no warnings 'misc' ; 917$x = 1 if $x = each %a ; 918EXPECT 919Value of each() operator can be "0"; test with defined() at - line 4. 920######## 921# op.c 922use warnings 'misc' ; 923$x = 1 while $x = <*> and 0 ; 924no warnings 'misc' ; 925$x = 1 while $x = <*> and 0 ; 926EXPECT 927Value of glob construct can be "0"; test with defined() at - line 3. 928######## 929# op.c 930use warnings 'misc' ; 931opendir FH, "." ; 932$x = 1 while $x = readdir FH and 0 ; 933no warnings 'misc' ; 934$x = 1 while $x = readdir FH and 0 ; 935closedir FH ; 936EXPECT 937Value of readdir() operator can be "0"; test with defined() at - line 4. 938######## 939# op.c 940use warnings 'misc'; 941open FH, "<abc"; 942($_ = <FH>) // ($_ = 1); 943opendir DH, "."; 944%a = (1,2,3,4) ; 945EXPECT 946######## 947# op.c 948use warnings 'redefine' ; 949sub fred {} 950sub fred {} 951sub fred { # warning should be for this line 952} 953no warnings 'redefine' ; 954sub fred {} 955sub fred { 956} 957EXPECT 958Subroutine fred redefined at - line 4. 959Subroutine fred redefined at - line 5. 960######## 961# op.c 962use warnings 'redefine' ; 963sub fred () { 1 } 964sub fred () { 1 } 965no warnings 'redefine' ; 966sub fred () { 1 } 967EXPECT 968Constant subroutine fred redefined at - line 4. 969######## 970# op.c 971sub fred () { 1 } 972sub fred () { 2 } 973EXPECT 974Constant subroutine fred redefined at - line 3. 975######## 976# op.c 977sub fred () { 1 } 978*fred = sub () { 2 }; 979EXPECT 980Constant subroutine main::fred redefined at - line 3. 981######## 982# op.c 983use feature "lexical_subs", "state"; 984my sub fred () { 1 } 985sub fred { 2 }; 986my sub george { 1 } 987sub george () { 2 } # should *not* produce redef warnings by default 988state sub phred () { 1 } 989sub phred { 2 }; 990state sub jorge { 1 } 991sub jorge () { 2 } # should *not* produce redef warnings by default 992EXPECT 993The lexical_subs feature is experimental at - line 3. 994Prototype mismatch: sub fred () vs none at - line 4. 995Constant subroutine fred redefined at - line 4. 996The lexical_subs feature is experimental at - line 5. 997Prototype mismatch: sub george: none vs () at - line 6. 998The lexical_subs feature is experimental at - line 7. 999Prototype mismatch: sub phred () vs none at - line 8. 1000Constant subroutine phred redefined at - line 8. 1001The lexical_subs feature is experimental at - line 9. 1002Prototype mismatch: sub jorge: none vs () at - line 10. 1003######## 1004# op.c 1005no warnings 'redefine' ; 1006sub fred () { 1 } 1007sub fred () { 2 } 1008EXPECT 1009######## 1010# op.c 1011no warnings 'redefine' ; 1012sub fred () { 1 } 1013*fred = sub () { 2 }; 1014EXPECT 1015######## 1016# op.c 1017use warnings 'redefine' ; 1018format FRED = 1019. 1020format FRED = 1021. 1022no warnings 'redefine' ; 1023format FRED = 1024. 1025EXPECT 1026Format FRED redefined at - line 5. 1027######## 1028# op.c 1029push FRED; 1030no warnings 'deprecated' ; 1031push FRED; 1032EXPECT 1033Array @FRED missing the @ in argument 1 of push() at - line 2. 1034######## 1035# op.c [Perl_ck_fun] 1036$fred = []; 1037push $fred; 1038pop $fred; 1039shift $fred; 1040unshift $fred; 1041splice $fred; 1042no warnings 'experimental::autoderef' ; 1043push $fred; 1044pop $fred; 1045shift $fred; 1046unshift $fred; 1047splice $fred; 1048EXPECT 1049push on reference is experimental at - line 3. 1050pop on reference is experimental at - line 4. 1051shift on reference is experimental at - line 5. 1052unshift on reference is experimental at - line 6. 1053splice on reference is experimental at - line 7. 1054######## 1055# op.c 1056@a = keys FRED ; 1057no warnings 'deprecated' ; 1058@a = keys FRED ; 1059EXPECT 1060Hash %FRED missing the % in argument 1 of keys() at - line 2. 1061######## 1062# op.c 1063use warnings 'exec' ; 1064exec "$^X -e 1" ; 1065my $a 1066EXPECT 1067Statement unlikely to be reached at - line 4. 1068 (Maybe you meant system() when you said exec()?) 1069######## 1070# op.c, no warning if exec isn't a statement. 1071use warnings 'exec' ; 1072$a || exec "$^X -e 1" ; 1073my $a 1074EXPECT 1075######## 1076# op.c 1077defined(@a); 1078EXPECT 1079defined(@array) is deprecated at - line 2. 1080 (Maybe you should just omit the defined()?) 1081######## 1082# op.c 1083my @a; defined(@a); 1084EXPECT 1085defined(@array) is deprecated at - line 2. 1086 (Maybe you should just omit the defined()?) 1087######## 1088# op.c 1089defined(@a = (1,2,3)); 1090EXPECT 1091defined(@array) is deprecated at - line 2. 1092 (Maybe you should just omit the defined()?) 1093######## 1094# op.c 1095defined(%h); 1096EXPECT 1097defined(%hash) is deprecated at - line 2. 1098 (Maybe you should just omit the defined()?) 1099######## 1100# op.c 1101my %h; defined(%h); 1102EXPECT 1103defined(%hash) is deprecated at - line 2. 1104 (Maybe you should just omit the defined()?) 1105######## 1106# op.c 1107no warnings 'exec' ; 1108exec "$^X -e 1" ; 1109my $a 1110EXPECT 1111 1112######## 1113# op.c 1114sub fred(); 1115sub fred($) {} 1116use constant foo=>bar; sub foo(@); 1117use constant bav=>bar; sub bav(); # no warning 1118sub btu; sub btu(); 1119EXPECT 1120Prototype mismatch: sub main::fred () vs ($) at - line 3. 1121Prototype mismatch: sub foo () vs (@) at - line 4. 1122Prototype mismatch: sub btu: none vs () at - line 6. 1123######## 1124# op.c 1125use utf8; 1126use open qw( :utf8 :std ); 1127sub frèd(); 1128sub frèd($) {} 1129EXPECT 1130Prototype mismatch: sub main::frèd () vs ($) at - line 5. 1131######## 1132# op.c 1133use utf8; 1134use open qw( :utf8 :std ); 1135use warnings; 1136eval "sub fòò (@\$\0) {}"; 1137EXPECT 1138Prototype after '@' for main::fòò : @$\0 at (eval 1) line 1. 1139Illegal character in prototype for main::fòò : @$\0 at (eval 1) line 1. 1140######## 1141# op.c 1142use utf8; 1143use open qw( :utf8 :std ); 1144use warnings; 1145eval "sub foo (@\0) {}"; 1146EXPECT 1147Prototype after '@' for main::foo : @\0 at (eval 1) line 1. 1148Illegal character in prototype for main::foo : @\0 at (eval 1) line 1. 1149######## 1150# op.c 1151use utf8; 1152use open qw( :utf8 :std ); 1153use warnings; 1154BEGIN { $::{"foo"} = "\@\$\0L\351on" } 1155BEGIN { eval "sub foo (@\$\0L\x{c3}\x{a9}on) {}"; } 1156EXPECT 1157Prototype after '@' for main::foo : @$\x{0}L... at (eval 1) line 1. 1158Illegal character in prototype for main::foo : @$\x{0}L... at (eval 1) line 1. 1159######## 1160# op.c 1161use utf8; 1162use open qw( :utf8 :std ); 1163use warnings; 1164BEGIN { eval "sub foo (@\0) {}"; } 1165EXPECT 1166Prototype after '@' for main::foo : @\0 at (eval 1) line 1. 1167Illegal character in prototype for main::foo : @\0 at (eval 1) line 1. 1168######## 1169# op.c 1170use warnings; 1171eval "sub foo (@\xAB) {}"; 1172EXPECT 1173Prototype after '@' for main::foo : @\x{ab} at (eval 1) line 1. 1174Illegal character in prototype for main::foo : @\x{ab} at (eval 1) line 1. 1175######## 1176# op.c 1177use utf8; 1178use open qw( :utf8 :std ); 1179use warnings; 1180BEGIN { eval "sub foo (@\x{30cb}) {}"; } 1181EXPECT 1182Prototype after '@' for main::foo : @\x{30cb} at (eval 1) line 1. 1183Illegal character in prototype for main::foo : @\x{30cb} at (eval 1) line 1. 1184######## 1185# op.c 1186use utf8; 1187use open qw( :utf8 :std ); 1188use warnings; 1189BEGIN { $::{"foo"} = "\x{30cb}" } 1190BEGIN { eval "sub foo {}"; } 1191EXPECT 1192Prototype mismatch: sub main::foo (ニ) vs none at (eval 1) line 1. 1193######## 1194# op.c 1195$^W = 0 ; 1196sub fred() ; 1197sub fred($) {} 1198{ 1199 no warnings 'prototype' ; 1200 sub Fred() ; 1201 sub Fred($) {} 1202 use warnings 'prototype' ; 1203 sub freD() ; 1204 sub freD($) {} 1205} 1206sub FRED() ; 1207sub FRED($) {} 1208EXPECT 1209Prototype mismatch: sub main::fred () vs ($) at - line 4. 1210Prototype mismatch: sub main::freD () vs ($) at - line 11. 1211Prototype mismatch: sub main::FRED () vs ($) at - line 14. 1212######## 1213# op.c [S_simplify_sort] 1214# [perl #86136] 1215my @tests = split /^/, ' 1216 sort {$a <=> $b} @a; 1217 sort {$a cmp $b} @a; 1218 { use integer; sort {$a <=> $b} @a} 1219 sort {$b <=> $a} @a; 1220 sort {$b cmp $a} @a; 1221 { use integer; sort {$b <=> $a} @a} 1222'; 1223for my $pragma ('use warnings "syntax";', '') { 1224 for my $vars ('', 'my $a;', 'my $b;', 'my ($a,$b);') { 1225 for my $inner_stmt ('', 'print;', 'func();') { 1226 eval "#line " . ++$line . "01 -\n$pragma\n$vars" 1227 . join "", map s/sort \{\K/$inner_stmt/r, @tests; 1228 $@ and die; 1229 } 1230 } 1231} 1232sub func{} 1233use warnings 'syntax'; 1234my $a; 1235# These used to be errors! 1236sort { ; } $a <=> $b; 1237sort { ; } $a, "<=>"; 1238sort { ; } $a, $cmp; 1239sort $a, $b if $cmpany_name; 1240sort if $a + $cmp; 1241sort @t; $a + $cmp; 1242EXPECT 1243"my $a" used in sort comparison at - line 403. 1244"my $a" used in sort comparison at - line 404. 1245"my $a" used in sort comparison at - line 405. 1246"my $a" used in sort comparison at - line 406. 1247"my $a" used in sort comparison at - line 407. 1248"my $a" used in sort comparison at - line 408. 1249"my $a" used in sort comparison at - line 503. 1250"my $a" used in sort comparison at - line 504. 1251"my $a" used in sort comparison at - line 505. 1252"my $a" used in sort comparison at - line 506. 1253"my $a" used in sort comparison at - line 507. 1254"my $a" used in sort comparison at - line 508. 1255"my $a" used in sort comparison at - line 603. 1256"my $a" used in sort comparison at - line 604. 1257"my $a" used in sort comparison at - line 605. 1258"my $a" used in sort comparison at - line 606. 1259"my $a" used in sort comparison at - line 607. 1260"my $a" used in sort comparison at - line 608. 1261"my $b" used in sort comparison at - line 703. 1262"my $b" used in sort comparison at - line 704. 1263"my $b" used in sort comparison at - line 705. 1264"my $b" used in sort comparison at - line 706. 1265"my $b" used in sort comparison at - line 707. 1266"my $b" used in sort comparison at - line 708. 1267"my $b" used in sort comparison at - line 803. 1268"my $b" used in sort comparison at - line 804. 1269"my $b" used in sort comparison at - line 805. 1270"my $b" used in sort comparison at - line 806. 1271"my $b" used in sort comparison at - line 807. 1272"my $b" used in sort comparison at - line 808. 1273"my $b" used in sort comparison at - line 903. 1274"my $b" used in sort comparison at - line 904. 1275"my $b" used in sort comparison at - line 905. 1276"my $b" used in sort comparison at - line 906. 1277"my $b" used in sort comparison at - line 907. 1278"my $b" used in sort comparison at - line 908. 1279"my $a" used in sort comparison at - line 1003. 1280"my $b" used in sort comparison at - line 1003. 1281"my $a" used in sort comparison at - line 1004. 1282"my $b" used in sort comparison at - line 1004. 1283"my $a" used in sort comparison at - line 1005. 1284"my $b" used in sort comparison at - line 1005. 1285"my $b" used in sort comparison at - line 1006. 1286"my $a" used in sort comparison at - line 1006. 1287"my $b" used in sort comparison at - line 1007. 1288"my $a" used in sort comparison at - line 1007. 1289"my $b" used in sort comparison at - line 1008. 1290"my $a" used in sort comparison at - line 1008. 1291"my $a" used in sort comparison at - line 1103. 1292"my $b" used in sort comparison at - line 1103. 1293"my $a" used in sort comparison at - line 1104. 1294"my $b" used in sort comparison at - line 1104. 1295"my $a" used in sort comparison at - line 1105. 1296"my $b" used in sort comparison at - line 1105. 1297"my $b" used in sort comparison at - line 1106. 1298"my $a" used in sort comparison at - line 1106. 1299"my $b" used in sort comparison at - line 1107. 1300"my $a" used in sort comparison at - line 1107. 1301"my $b" used in sort comparison at - line 1108. 1302"my $a" used in sort comparison at - line 1108. 1303"my $a" used in sort comparison at - line 1203. 1304"my $b" used in sort comparison at - line 1203. 1305"my $a" used in sort comparison at - line 1204. 1306"my $b" used in sort comparison at - line 1204. 1307"my $a" used in sort comparison at - line 1205. 1308"my $b" used in sort comparison at - line 1205. 1309"my $b" used in sort comparison at - line 1206. 1310"my $a" used in sort comparison at - line 1206. 1311"my $b" used in sort comparison at - line 1207. 1312"my $a" used in sort comparison at - line 1207. 1313"my $b" used in sort comparison at - line 1208. 1314"my $a" used in sort comparison at - line 1208. 1315######## 1316# op.c [S_simplify_sort] 1317use warnings 'syntax'; use 5.01; 1318state $a; 1319sort { $a <=> $b } (); 1320EXPECT 1321"state $a" used in sort comparison at - line 4. 1322######## 1323# op.c [Perl_ck_cmp] 1324use warnings 'syntax' ; 1325no warnings 'deprecated'; 1326@a = $[ < 5; 1327@a = $[ > 5; 1328@a = $[ <= 5; 1329@a = $[ >= 5; 1330@a = 42 < $[; 1331@a = 42 > $[; 1332@a = 42 <= $[; 1333@a = 42 >= $[; 1334use integer; 1335@a = $[ < 5; 1336@a = $[ > 5; 1337@a = $[ <= 5; 1338@a = $[ >= 5; 1339@a = 42 < $[; 1340@a = 42 > $[; 1341@a = 42 <= $[; 1342@a = 42 >= $[; 1343no integer; 1344@a = $[ < $5; 1345@a = $[ > $5; 1346@a = $[ <= $5; 1347@a = $[ >= $5; 1348@a = $42 < $[; 1349@a = $42 > $[; 1350@a = $42 <= $[; 1351@a = $42 >= $[; 1352use integer; 1353@a = $[ < $5; 1354@a = $[ > $5; 1355@a = $[ <= $5; 1356@a = $[ >= $5; 1357@a = $42 < $[; 1358@a = $42 > $[; 1359@a = $42 <= $[; 1360@a = $42 >= $[; 1361EXPECT 1362$[ used in numeric lt (<) (did you mean $] ?) at - line 4. 1363$[ used in numeric gt (>) (did you mean $] ?) at - line 5. 1364$[ used in numeric le (<=) (did you mean $] ?) at - line 6. 1365$[ used in numeric ge (>=) (did you mean $] ?) at - line 7. 1366$[ used in numeric lt (<) (did you mean $] ?) at - line 8. 1367$[ used in numeric gt (>) (did you mean $] ?) at - line 9. 1368$[ used in numeric le (<=) (did you mean $] ?) at - line 10. 1369$[ used in numeric ge (>=) (did you mean $] ?) at - line 11. 1370$[ used in numeric lt (<) (did you mean $] ?) at - line 13. 1371$[ used in numeric gt (>) (did you mean $] ?) at - line 14. 1372$[ used in numeric le (<=) (did you mean $] ?) at - line 15. 1373$[ used in numeric ge (>=) (did you mean $] ?) at - line 16. 1374$[ used in numeric lt (<) (did you mean $] ?) at - line 17. 1375$[ used in numeric gt (>) (did you mean $] ?) at - line 18. 1376$[ used in numeric le (<=) (did you mean $] ?) at - line 19. 1377$[ used in numeric ge (>=) (did you mean $] ?) at - line 20. 1378######## 1379# op.c [Perl_ck_each] 1380$fred = {}; 1381keys $fred; 1382values $fred; 1383each $fred; 1384no warnings 'experimental::autoderef' ; 1385keys $fred; 1386values $fred; 1387each $fred; 1388EXPECT 1389keys on reference is experimental at - line 3. 1390values on reference is experimental at - line 4. 1391each on reference is experimental at - line 5. 1392######## 1393# op.c [Perl_ck_length] 1394use warnings 'syntax' ; 1395length(@a); 1396length(%b); 1397length(@$c); 1398length(%$d); 1399length($a); 1400length(my %h); 1401length(my @g); 1402EXPECT 1403length() used on @a (did you mean "scalar(@a)"?) at - line 3. 1404length() used on %b (did you mean "scalar(keys %b)"?) at - line 4. 1405length() used on @array (did you mean "scalar(@array)"?) at - line 5. 1406length() used on %hash (did you mean "scalar(keys %hash)"?) at - line 6. 1407length() used on %h (did you mean "scalar(keys %h)"?) at - line 8. 1408length() used on @g (did you mean "scalar(@g)"?) at - line 9. 1409######## 1410# op.c 1411use warnings 'syntax' ; 1412join /---/, 'x', 'y', 'z'; 1413EXPECT 1414/---/ should probably be written as "---" at - line 3. 1415######## 1416# op.c 1417use utf8; 1418use open qw( :utf8 :std ); 1419use warnings 'syntax' ; 1420join /~~~/, 'x', 'y', 'z'; 1421EXPECT 1422/~~~/ should probably be written as "~~~" at - line 5. 1423######## 1424# op.c [Perl_peep] 1425use warnings 'prototype' ; 1426fred() ; 1427sub fred ($$) {} 1428no warnings 'prototype' ; 1429joe() ; 1430sub joe ($$) {} 1431EXPECT 1432main::fred() called too early to check prototype at - line 3. 1433######## 1434# op.c [Perl_newATTRSUB] 1435--FILE-- abc.pm 1436use warnings 'void' ; 1437BEGIN { $| = 1; print "in begin\n"; } 1438CHECK { print "in check\n"; } 1439INIT { print "in init\n"; } 1440END { print "in end\n"; } 1441print "in mainline\n"; 14421; 1443--FILE-- 1444use abc; 1445delete $INC{"abc.pm"}; 1446require abc; 1447do "abc.pm"; 1448EXPECT 1449in begin 1450in mainline 1451in check 1452in init 1453in begin 1454Too late to run CHECK block at abc.pm line 3. 1455Too late to run INIT block at abc.pm line 4. 1456in mainline 1457in begin 1458Too late to run CHECK block at abc.pm line 3. 1459Too late to run INIT block at abc.pm line 4. 1460in mainline 1461in end 1462in end 1463in end 1464######## 1465# op.c [Perl_newATTRSUB] 1466--FILE-- abc.pm 1467no warnings 'void' ; 1468BEGIN { $| = 1; print "in begin\n"; } 1469CHECK { print "in check\n"; } 1470INIT { print "in init\n"; } 1471END { print "in end\n"; } 1472print "in mainline\n"; 14731; 1474--FILE-- 1475require abc; 1476do "abc.pm"; 1477EXPECT 1478in begin 1479in mainline 1480in begin 1481in mainline 1482in end 1483in end 1484######## 1485# op.c 1486my @x; 1487use warnings 'syntax' ; 1488push(@x); 1489unshift(@x); 1490no warnings 'syntax' ; 1491push(@x); 1492unshift(@x); 1493EXPECT 1494Useless use of push with no values at - line 4. 1495Useless use of unshift with no values at - line 5. 1496######## 1497# op.c 1498# 20020401 mjd@plover.com at suggestion of jfriedl@yahoo.com 1499use warnings 'regexp'; 1500split /blah/g, "blah"; 1501no warnings 'regexp'; 1502split /blah/g, "blah"; 1503EXPECT 1504Use of /g modifier is meaningless in split at - line 4. 1505######## 1506# op.c 1507use warnings 'precedence'; 1508$a = $b & $c == $d; 1509$a = $b ^ $c != $d; 1510$a = $b | $c > $d; 1511$a = $b < $c & $d; 1512$a = $b >= $c ^ $d; 1513$a = $b <= $c | $d; 1514$a = $b <=> $c & $d; 1515$a &= $b == $c; $a |= $b == $c; $a ^= $b == $c; # shouldn't warn 1516no warnings 'precedence'; 1517$a = $b & $c == $d; 1518$a = $b ^ $c != $d; 1519$a = $b | $c > $d; 1520$a = $b < $c & $d; 1521$a = $b >= $c ^ $d; 1522$a = $b <= $c | $d; 1523$a = $b <=> $c & $d; 1524EXPECT 1525Possible precedence problem on bitwise & operator at - line 3. 1526Possible precedence problem on bitwise ^ operator at - line 4. 1527Possible precedence problem on bitwise | operator at - line 5. 1528Possible precedence problem on bitwise & operator at - line 6. 1529Possible precedence problem on bitwise ^ operator at - line 7. 1530Possible precedence problem on bitwise | operator at - line 8. 1531Possible precedence problem on bitwise & operator at - line 9. 1532######## 1533# op.c 1534use integer; 1535use warnings 'precedence'; 1536$a = $b & $c == $d; 1537$a = $b ^ $c != $d; 1538$a = $b | $c > $d; 1539$a = $b < $c & $d; 1540$a = $b >= $c ^ $d; 1541$a = $b <= $c | $d; 1542$a = $b <=> $c & $d; 1543no warnings 'precedence'; 1544$a = $b & $c == $d; 1545$a = $b ^ $c != $d; 1546$a = $b | $c > $d; 1547$a = $b < $c & $d; 1548$a = $b >= $c ^ $d; 1549$a = $b <= $c | $d; 1550$a = $b <=> $c & $d; 1551EXPECT 1552Possible precedence problem on bitwise & operator at - line 4. 1553Possible precedence problem on bitwise ^ operator at - line 5. 1554Possible precedence problem on bitwise | operator at - line 6. 1555Possible precedence problem on bitwise & operator at - line 7. 1556Possible precedence problem on bitwise ^ operator at - line 8. 1557Possible precedence problem on bitwise | operator at - line 9. 1558Possible precedence problem on bitwise & operator at - line 10. 1559######## 1560# op.c 1561 1562# ok => local() has desired effect; 1563# ignore=> local() silently ignored 1564 1565use warnings 'syntax'; 1566 1567local(undef); # OP_UNDEF ignore 1568sub lval : lvalue {}; 1569local(lval()); # OP_ENTERSUB 1570local($x **= 1); # OP_POW 1571local($x *= 1); # OP_MULTIPLY 1572local($x /= 1); # OP_DIVIDE 1573local($x %= 1); # OP_MODULO 1574local($x x= 1); # OP_REPEAT 1575local($x += 1); # OP_ADD 1576local($x -= 1); # OP_SUBTRACT 1577local($x .= 1); # OP_CONCAT 1578local($x <<= 1); # OP_LEFT_SHIFT 1579local($x >>= 1); # OP_RIGHT_SHIFT 1580local($x &= 1); # OP_BIT_AND 1581local($x ^= 1); # OP_BIT_XOR 1582local($x |= 1); # OP_BIT_OR 1583{ 1584 use integer; 1585 local($x *= 1); # OP_I_MULTIPLY 1586 local($x /= 1); # OP_I_DIVIDE 1587 local($x %= 1); # OP_I_MODULO 1588 local($x += 1); # OP_I_ADD 1589 local($x -= 1); # OP_I_SUBTRACT 1590} 1591local($x?$y:$z) = 1; # OP_COND_EXPR ok 1592# these two are fatal run-time errors instead 1593#local(@$a); # OP_RV2AV ok 1594#local(%$a); # OP_RV2HV ok 1595local(*a); # OP_RV2GV ok 1596local(@a[1,2]); # OP_ASLICE ok 1597local(@a{1,2}); # OP_HSLICE ok 1598local(@a = (1,2)); # OP_AASSIGN 1599local($$x); # OP_RV2SV ok 1600local($#a); # OP_AV2ARYLEN 1601local($x = 1); # OP_SASSIGN 1602local($x &&= 1); # OP_ANDASSIGN 1603local($x ||= 1); # OP_ORASSIGN 1604local($x //= 1); # OP_DORASSIGN 1605local($a[0]); # OP_AELEMFAST ok 1606 1607local(substr($x,0,1)); # OP_SUBSTR 1608local(pos($x)); # OP_POS 1609local(vec($x,0,1)); # OP_VEC 1610local($a[$b]); # OP_AELEM ok 1611local($a{$b}); # OP_HELEM ok 1612 1613no warnings 'syntax'; 1614EXPECT 1615Useless localization of subroutine entry at - line 10. 1616Useless localization of exponentiation (**) at - line 11. 1617Useless localization of multiplication (*) at - line 12. 1618Useless localization of division (/) at - line 13. 1619Useless localization of modulus (%) at - line 14. 1620Useless localization of repeat (x) at - line 15. 1621Useless localization of addition (+) at - line 16. 1622Useless localization of subtraction (-) at - line 17. 1623Useless localization of concatenation (.) or string at - line 18. 1624Useless localization of left bitshift (<<) at - line 19. 1625Useless localization of right bitshift (>>) at - line 20. 1626Useless localization of bitwise and (&) at - line 21. 1627Useless localization of bitwise xor (^) at - line 22. 1628Useless localization of bitwise or (|) at - line 23. 1629Useless localization of integer multiplication (*) at - line 26. 1630Useless localization of integer division (/) at - line 27. 1631Useless localization of integer modulus (%) at - line 28. 1632Useless localization of integer addition (+) at - line 29. 1633Useless localization of integer subtraction (-) at - line 30. 1634Useless localization of list assignment at - line 39. 1635Useless localization of array length at - line 41. 1636Useless localization of scalar assignment at - line 42. 1637Useless localization of logical and assignment (&&=) at - line 43. 1638Useless localization of logical or assignment (||=) at - line 44. 1639Useless localization of defined or assignment (//=) at - line 45. 1640Useless localization of substr at - line 48. 1641Useless localization of match position at - line 49. 1642Useless localization of vec at - line 50. 1643######## 1644# op.c 1645my $x1 if 0; 1646my @x2 if 0; 1647my %x3 if 0; 1648my ($x4) if 0; 1649my ($x5,@x6, %x7) if 0; 16500 && my $z1; 16510 && my (%z2); 1652# these shouldn't warn 1653our $x if 0; 1654our $x unless 0; 1655if (0) { my $w1 } 1656if (my $w2) { $a=1 } 1657if ($a && (my $w3 = 1)) {$a = 2} 1658 1659EXPECT 1660Deprecated use of my() in false conditional at - line 2. 1661Deprecated use of my() in false conditional at - line 3. 1662Deprecated use of my() in false conditional at - line 4. 1663Deprecated use of my() in false conditional at - line 5. 1664Deprecated use of my() in false conditional at - line 6. 1665Deprecated use of my() in false conditional at - line 7. 1666Deprecated use of my() in false conditional at - line 8. 1667######## 1668# op.c 1669$[ = 1; 1670($[) = 1; 1671use warnings 'deprecated'; 1672$[ = 2; 1673($[) = 2; 1674no warnings 'deprecated'; 1675$[ = 3; 1676($[) = 3; 1677EXPECT 1678Use of assignment to $[ is deprecated at - line 2. 1679Use of assignment to $[ is deprecated at - line 3. 1680Use of assignment to $[ is deprecated at - line 5. 1681Use of assignment to $[ is deprecated at - line 6. 1682######## 1683# op.c 1684use warnings 'void'; 1685@x = split /y/, "z"; 1686$x = split /y/, "z"; 1687 split /y/, "z"; 1688no warnings 'void'; 1689@x = split /y/, "z"; 1690$x = split /y/, "z"; 1691 split /y/, "z"; 1692EXPECT 1693Useless use of split in void context at - line 5. 1694######## 1695# op.c 1696use warnings 'redefine' ; 1697use utf8; 1698use open qw( :utf8 :std ); 1699sub frèd {} 1700sub frèd {} 1701no warnings 'redefine' ; 1702sub frèd {} 1703EXPECT 1704Subroutine frèd redefined at - line 6. 1705######## 1706# op.c 1707use warnings 'redefine' ; 1708use utf8; 1709use open qw( :utf8 :std ); 1710sub frèd () { 1 } 1711sub frèd () { 1 } 1712no warnings 'redefine' ; 1713sub frèd () { 1 } 1714EXPECT 1715Constant subroutine frèd redefined at - line 6. 1716######## 1717# op.c 1718use utf8; 1719use open qw( :utf8 :std ); 1720sub frèd () { 1 } 1721sub frèd () { 2 } 1722EXPECT 1723Constant subroutine frèd redefined at - line 5. 1724######## 1725# op.c 1726use utf8; 1727use open qw( :utf8 :std ); 1728sub frèd () { 1 } 1729*frèd = sub () { 2 }; 1730EXPECT 1731Constant subroutine main::frèd redefined at - line 5. 1732######## 1733# op.c 1734use warnings 'redefine' ; 1735use utf8; 1736use open qw( :utf8 :std ); 1737sub ᚠርƊ {} 1738sub ᚠርƊ {} 1739no warnings 'redefine' ; 1740sub ᚠርƊ {} 1741EXPECT 1742Subroutine ᚠርƊ redefined at - line 6. 1743######## 1744# op.c 1745use warnings 'redefine' ; 1746use utf8; 1747use open qw( :utf8 :std ); 1748sub ᚠርƊ () { 1 } 1749sub ᚠርƊ () { 1 } 1750no warnings 'redefine' ; 1751sub ᚠርƊ () { 1 } 1752EXPECT 1753Constant subroutine ᚠርƊ redefined at - line 6. 1754######## 1755# op.c 1756use utf8; 1757use open qw( :utf8 :std ); 1758sub ᚠርƊ () { 1 } 1759sub ᚠርƊ () { 2 } 1760EXPECT 1761Constant subroutine ᚠርƊ redefined at - line 5. 1762######## 1763# op.c 1764use utf8; 1765use open qw( :utf8 :std ); 1766sub ᚠርƊ () { 1 } 1767*ᚠርƊ = sub () { 2 }; 1768EXPECT 1769Constant subroutine main::ᚠርƊ redefined at - line 5. 1770######## 1771# OPTION regex 1772sub DynaLoader::dl_error {}; 1773use warnings; 1774# We're testing that the warnings report the same line number: 1775eval <<'EOC' or die $@; 1776{ 1777 DynaLoader::boot_DynaLoader("DynaLoader"); 1778} 1779EOC 1780eval <<'EOC' or die $@; 1781BEGIN { 1782 DynaLoader::boot_DynaLoader("DynaLoader"); 1783} 17841 1785EOC 1786EXPECT 1787OPTION regex 1788\ASubroutine DynaLoader::dl_error redefined at \(eval 1\) line 2\. 1789?(?s).* 1790Subroutine DynaLoader::dl_error redefined at \(eval 2\) line 2\. 1791######## 1792# op.c 1793use warnings; 1794sub do_warn_1 { return $a or $b; } 1795sub do_warn_2 { return $a and $b; } 1796sub do_warn_3 { return $a xor $b; } 1797sub do_warn_4 { die $a or $b; } 1798sub do_warn_5 { die $a and $b; } 1799sub do_warn_6 { die $a xor $b; } 1800sub do_warn_7 { exit $a or $b; } 1801sub do_warn_8 { exit $a and $b; } 1802sub do_warn_9 { exit $a xor $b; } 1803 1804# Since exit is an unary operator, it is even stronger than 1805# || and &&. 1806sub do_warn_10 { exit $a || $b; } 1807sub do_warn_11 { exit $a && $b; } 1808 1809sub do_warn_12 { goto $a or $b; } 1810sub do_warn_13 { goto $a and $b; } 1811sub do_warn_14 { goto $a xor $b; } 1812sub do_warn_15 { next $a or $b while(1); } 1813sub do_warn_16 { next $a and $b while(1); } 1814sub do_warn_17 { next $a xor $b while(1); } 1815sub do_warn_18 { last $a or $b while(1); } 1816sub do_warn_19 { last $a and $b while(1); } 1817sub do_warn_20 { last $a xor $b while(1); } 1818sub do_warn_21 { redo $a or $b while(1); } 1819sub do_warn_22 { redo $a and $b while(1); } 1820sub do_warn_23 { redo $a xor $b while(1); } 1821# These get re-written to "(return/die $a) and $b" 1822sub do_warn_24 { $b if return $a; } 1823sub do_warn_25 { $b if die $a; } 1824EXPECT 1825Possible precedence issue with control flow operator at - line 3. 1826Possible precedence issue with control flow operator at - line 4. 1827Possible precedence issue with control flow operator at - line 5. 1828Possible precedence issue with control flow operator at - line 6. 1829Possible precedence issue with control flow operator at - line 7. 1830Possible precedence issue with control flow operator at - line 8. 1831Possible precedence issue with control flow operator at - line 9. 1832Possible precedence issue with control flow operator at - line 10. 1833Possible precedence issue with control flow operator at - line 11. 1834Possible precedence issue with control flow operator at - line 15. 1835Possible precedence issue with control flow operator at - line 16. 1836Possible precedence issue with control flow operator at - line 18. 1837Possible precedence issue with control flow operator at - line 19. 1838Possible precedence issue with control flow operator at - line 20. 1839Possible precedence issue with control flow operator at - line 21. 1840Possible precedence issue with control flow operator at - line 22. 1841Possible precedence issue with control flow operator at - line 23. 1842Possible precedence issue with control flow operator at - line 24. 1843Possible precedence issue with control flow operator at - line 25. 1844Possible precedence issue with control flow operator at - line 26. 1845Possible precedence issue with control flow operator at - line 27. 1846Possible precedence issue with control flow operator at - line 28. 1847Possible precedence issue with control flow operator at - line 29. 1848Possible precedence issue with control flow operator at - line 31. 1849Possible precedence issue with control flow operator at - line 32. 1850######## 1851# op.c 1852# (same as above, except these should not warn) 1853use constant FEATURE => 1; 1854use constant MISSING_FEATURE => 0; 1855 1856sub dont_warn_1 { MISSING_FEATURE and return or dont_warn_3(); } 1857sub dont_warn_2 { FEATURE || return and dont_warn_3(); } 1858sub dont_warn_3 { not FEATURE and return or dont_warn_3(); } 1859sub dont_warn_4 { !MISSING_FEATURE || return and dont_warn_3(); } 1860sub dont_warn_5 { MISSING_FEATURE and die or dont_warn_3(); } 1861sub dont_warn_6 { FEATURE || die and dont_warn_3(); } 1862sub dont_warn_7 { not FEATURE and die or dont_warn_3(); } 1863sub dont_warn_8 { !MISSING_FEATURE || die and dont_warn_3(); } 1864sub dont_warn_9 { MISSING_FEATURE and goto $a or dont_warn_3(); } 1865sub dont_warn_10 { FEATURE || goto $a and dont_warn_3(); } 1866sub dont_warn_11 { not FEATURE and goto $a or dont_warn_3(); } 1867sub dont_warn_12 { !MISSING_FEATURE || goto $a and dont_warn_3(); } 1868 1869sub dont_warn_13 { MISSING_FEATURE and exit $a or dont_warn_3(); } 1870sub dont_warn_14 { FEATURE || exit $a and dont_warn_3(); } 1871sub dont_warn_15 { not FEATURE and exit $a or dont_warn_3(); } 1872sub dont_warn_16 { !MISSING_FEATURE || exit $a and dont_warn_3(); } 1873 1874sub dont_warn_17 { MISSING_FEATURE and next or dont_warn_3() while(1); } 1875sub dont_warn_18 { FEATURE || next and dont_warn_3() while(1); } 1876sub dont_warn_19 { not FEATURE and next or dont_warn_3() while(1); } 1877sub dont_warn_20 { !MISSING_FEATURE || next and dont_warn_3() while(1); } 1878sub dont_warn_21 { MISSING_FEATURE and redo or dont_warn_3() while(1); } 1879sub dont_warn_22 { FEATURE || redo and dont_warn_3() while(1); } 1880sub dont_warn_23 { not FEATURE and redo or dont_warn_3() while(1); } 1881sub dont_warn_24 { !MISSING_FEATURE || redo and dont_warn_3() while(1); } 1882sub dont_warn_25 { MISSING_FEATURE and last or dont_warn_3() while(1); } 1883sub dont_warn_26 { FEATURE || last and dont_warn_3() while(1); } 1884sub dont_warn_27 { not FEATURE and last or dont_warn_3() while(1); } 1885sub dont_warn_28 { !MISSING_FEATURE || last and dont_warn_3() while(1); } 1886 1887# These are weird, but at least not ambiguous. 1888sub dont_warn_29 { return ($a or $b); } 1889sub dont_warn_30 { return ($a and $b); } 1890sub dont_warn_31 { return ($a xor $b); } 1891sub dont_warn_32 { die ($a or $b); } 1892sub dont_warn_33 { die ($a and $b); } 1893sub dont_warn_34 { die ($a xor $b); } 1894sub dont_warn_35 { goto ($a or $b); } 1895sub dont_warn_36 { goto ($a and $b); } 1896sub dont_warn_37 { goto ($a xor $b); } 1897sub dont_warn_38 { next ($a or $b) while(1); } 1898sub dont_warn_39 { next ($a and $b) while(1); } 1899sub dont_warn_40 { next ($a xor $b) while(1); } 1900sub dont_warn_41 { last ($a or $b) while(1); } 1901sub dont_warn_42 { last ($a and $b) while(1); } 1902sub dont_warn_43 { last ($a xor $b) while(1); } 1903sub dont_warn_44 { redo ($a or $b) while(1); } 1904sub dont_warn_45 { redo ($a and $b) while(1); } 1905sub dont_warn_46 { redo ($a xor $b) while(1); } 1906EXPECT 1907######## 1908use feature "signatures"; 1909sub aaa { 2 } 1910sub bbb ($a) { 4 } 1911$aaa = sub { 2 }; 1912$bbb = sub ($a) { 4 }; 1913EXPECT 1914The signatures feature is experimental at - line 3. 1915The signatures feature is experimental at - line 5. 1916######## 1917no warnings "experimental::signatures"; 1918use feature "signatures"; 1919sub aaa { 2 } 1920sub bbb ($a) { 4 } 1921$aaa = sub { 2 }; 1922$bbb = sub ($a) { 4 }; 1923EXPECT 1924