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