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