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