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