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