This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fatalize using hash|array as reference
[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
f10b0346 74 defined(@array) is deprecated
cc507455 75 (Maybe you should just omit the defined()?)
69794302
MJD
76 my @a ; defined @a ;
77 defined (@a = (1,2,3)) ;
78
f10b0346 79 defined(%hash) is deprecated
cc507455 80 (Maybe you should just omit the defined()?)
69794302 81 my %h ; defined %h ;
89474f50 82
271c8bde
FC
83 "my %s" used in sort comparison
84
89474f50 85 $[ used in comparison (did you mean $] ?)
e508c8a4 86
0953b66b
FC
87 each on reference is experimental [ck_each]
88 keys on reference is experimental
89 values on reference is experimental
90
e508c8a4
MH
91 length() used on @array (did you mean "scalar(@array)"?)
92 length() used on %hash (did you mean "scalar(keys %hash)"?)
93
eb6e2d6f
GS
94 /---/ should probably be written as "---"
95 join(/---/, @foo);
599cee73 96
767a6a26
PM
97 %s() called too early to check prototype [Perl_peep]
98 fred() ; sub fred ($$) {}
99
100
15a8c21e 101 Package '%s' not found (did you use the incorrect case?)
3b434eb1 102
f34840d8
MJD
103 Use of /g modifier is meaningless in split
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
372\@a ; # OP_REFGEN
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
392join "" ; # OP_JOIN
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
FC
419use 5.015;
420__SUB__ # OP_RUNCV
599cee73 421EXPECT
baed7faa 422Useless use of a constant ("111") in void context at - line 2.
42d38218 423Useless use of repeat (x) in void context at - line 3.
599cee73
PM
424Useless use of wantarray in void context at - line 5.
425Useless use of reference-type operator in void context at - line 12.
426Useless use of reference constructor in void context at - line 13.
d6c467eb 427Useless use of single ref constructor in void context at - line 14.
599cee73
PM
428Useless use of defined operator in void context at - line 15.
429Useless use of hex in void context at - line 16.
430Useless use of oct in void context at - line 17.
431Useless use of length in void context at - line 18.
432Useless use of substr in void context at - line 19.
433Useless use of vec in void context at - line 20.
434Useless use of index in void context at - line 21.
435Useless use of rindex in void context at - line 22.
436Useless use of sprintf in void context at - line 23.
437Useless use of array element in void context at - line 24.
438Useless use of array slice in void context at - line 26.
f1612b5c 439Useless use of hash element in void context at - line 29.
599cee73
PM
440Useless use of hash slice in void context at - line 30.
441Useless use of unpack in void context at - line 31.
442Useless use of pack in void context at - line 32.
297b36dc 443Useless use of join or string in void context at - line 33.
599cee73
PM
444Useless use of list slice in void context at - line 34.
445Useless use of sort in void context at - line 37.
446Useless use of reverse in void context at - line 38.
447Useless use of range (or flop) in void context at - line 41.
448Useless use of caller in void context at - line 42.
449Useless use of fileno in void context at - line 43.
450Useless use of eof in void context at - line 44.
451Useless use of tell in void context at - line 45.
452Useless use of readlink in void context at - line 46.
453Useless use of time in void context at - line 47.
454Useless use of localtime in void context at - line 48.
455Useless use of gmtime in void context at - line 49.
456Useless use of getgrnam in void context at - line 50.
457Useless use of getgrgid in void context at - line 51.
458Useless use of getpwnam in void context at - line 52.
459Useless use of getpwuid in void context at - line 53.
78e1b766 460Useless use of subroutine prototype in void context at - line 54.
f5df4782
RGS
461Useless use of smart match in void context at - line 55.
462Useless use of numeric comparison (<=>) in void context at - line 56.
60282a49
KW
463Useless use of a constant ("dsatrewq") in void context at - line 57.
464Useless use of a constant ("diatrewq") in void context at - line 58.
465Useless use of a constant ("igatrewq") in void context at - line 59.
466Useless use of __SUB__ in void context at - line 61.
599cee73
PM
467########
468# op.c
a801c63c
RGS
469use warnings 'void' ; close STDIN ;
470my $x = sort (2,1,3);
471no warnings 'void' ;
472$x = sort (2,1,3);
473EXPECT
474Useless use of sort in scalar context at - line 3.
475########
476# op.c
4438c4b7 477no warnings 'void' ; close STDIN ;
0453d815
PM
4781 x 3 ; # OP_REPEAT
479 # OP_GVSV
480wantarray ; # OP_WANTARRAY
481 # OP_GV
482 # OP_PADSV
483 # OP_PADAV
484 # OP_PADHV
485 # OP_PADANY
486 # OP_AV2ARYLEN
487ref ; # OP_REF
488\@a ; # OP_REFGEN
489\$a ; # OP_SREFGEN
490defined $a ; # OP_DEFINED
491hex $a ; # OP_HEX
492oct $a ; # OP_OCT
493length $a ; # OP_LENGTH
494substr $a,1 ; # OP_SUBSTR
495vec $a,1,2 ; # OP_VEC
496index $a,1,2 ; # OP_INDEX
497rindex $a,1,2 ; # OP_RINDEX
498sprintf $a ; # OP_SPRINTF
499$a[0] ; # OP_AELEM
500 # OP_AELEMFAST
501@a[0] ; # OP_ASLICE
502#values %a ; # OP_VALUES
503#keys %a ; # OP_KEYS
504$a{0} ; # OP_HELEM
505@a{0} ; # OP_HSLICE
506unpack "a", "a" ; # OP_UNPACK
507pack $a,"" ; # OP_PACK
508join "" ; # OP_JOIN
509(@a)[0,1] ; # OP_LSLICE
510 # OP_ANONLIST
511 # OP_ANONHASH
512sort(1,2) ; # OP_SORT
513reverse(1,2) ; # OP_REVERSE
514 # OP_RANGE
515 # OP_FLIP
516(1 ..2) ; # OP_FLOP
517caller ; # OP_CALLER
518fileno STDIN ; # OP_FILENO
519eof STDIN ; # OP_EOF
520tell STDIN ; # OP_TELL
521readlink 1; # OP_READLINK
522time ; # OP_TIME
523localtime ; # OP_LOCALTIME
524gmtime ; # OP_GMTIME
525eval { getgrnam 1 }; # OP_GGRNAM
526eval { getgrgid 1 }; # OP_GGRGID
527eval { getpwnam 1 }; # OP_GPWNAM
528eval { getpwuid 1 }; # OP_GPWUID
78e1b766 529prototype "foo"; # OP_PROTOTYPE
0453d815
PM
530EXPECT
531########
532# op.c
4438c4b7 533use warnings 'void' ;
68c73484 534for (@{[0]}) { "$_" } # check warning isn't duplicated
4438c4b7 535no warnings 'void' ;
0453d815 536for (@{[0]}) { "$_" } # check warning isn't duplicated
68c73484
JH
537EXPECT
538Useless use of string in void context at - line 3.
539########
540# op.c
4438c4b7 541use warnings 'void' ;
599cee73
PM
542use Config ;
543BEGIN {
544 if ( ! $Config{d_telldir}) {
545 print <<EOM ;
546SKIPPED
547# telldir not present
548EOM
549 exit
550 }
551}
552telldir 1 ; # OP_TELLDIR
4438c4b7 553no warnings 'void' ;
0453d815 554telldir 1 ; # OP_TELLDIR
599cee73
PM
555EXPECT
556Useless use of telldir in void context at - line 13.
557########
558# op.c
4438c4b7 559use warnings 'void' ;
599cee73
PM
560use Config ;
561BEGIN {
562 if ( ! $Config{d_getppid}) {
563 print <<EOM ;
564SKIPPED
565# getppid not present
566EOM
567 exit
568 }
569}
570getppid ; # OP_GETPPID
4438c4b7 571no warnings 'void' ;
0453d815 572getppid ; # OP_GETPPID
599cee73
PM
573EXPECT
574Useless use of getppid in void context at - line 13.
575########
576# op.c
4438c4b7 577use warnings 'void' ;
599cee73
PM
578use Config ;
579BEGIN {
580 if ( ! $Config{d_getpgrp}) {
581 print <<EOM ;
582SKIPPED
583# getpgrp not present
584EOM
585 exit
586 }
587}
588getpgrp ; # OP_GETPGRP
4438c4b7 589no warnings 'void' ;
0453d815 590getpgrp ; # OP_GETPGRP
599cee73
PM
591EXPECT
592Useless use of getpgrp in void context at - line 13.
593########
594# op.c
4438c4b7 595use warnings 'void' ;
599cee73
PM
596use Config ;
597BEGIN {
598 if ( ! $Config{d_times}) {
599 print <<EOM ;
600SKIPPED
601# times not present
602EOM
603 exit
604 }
605}
606times ; # OP_TMS
4438c4b7 607no warnings 'void' ;
0453d815 608times ; # OP_TMS
599cee73
PM
609EXPECT
610Useless use of times in void context at - line 13.
611########
612# op.c
4438c4b7 613use warnings 'void' ;
599cee73
PM
614use Config ;
615BEGIN {
e96326af 616 if ( ! $Config{d_getprior} or $^O eq 'os2') { # Locks before fixpak22
599cee73
PM
617 print <<EOM ;
618SKIPPED
619# getpriority not present
620EOM
621 exit
622 }
623}
624getpriority 1,2; # OP_GETPRIORITY
4438c4b7 625no warnings 'void' ;
0453d815 626getpriority 1,2; # OP_GETPRIORITY
599cee73
PM
627EXPECT
628Useless use of getpriority in void context at - line 13.
629########
630# op.c
4438c4b7 631use warnings 'void' ;
599cee73
PM
632use Config ;
633BEGIN {
634 if ( ! $Config{d_getlogin}) {
635 print <<EOM ;
636SKIPPED
637# getlogin not present
638EOM
639 exit
640 }
641}
642getlogin ; # OP_GETLOGIN
4438c4b7 643no warnings 'void' ;
0453d815 644getlogin ; # OP_GETLOGIN
599cee73
PM
645EXPECT
646Useless use of getlogin in void context at - line 13.
647########
648# op.c
4438c4b7 649use warnings 'void' ;
599cee73
PM
650use Config ; BEGIN {
651if ( ! $Config{d_socket}) {
652 print <<EOM ;
653SKIPPED
654# getsockname not present
655# getpeername not present
656# gethostbyname not present
657# gethostbyaddr not present
658# gethostent not present
659# getnetbyname not present
660# getnetbyaddr not present
661# getnetent not present
662# getprotobyname not present
663# getprotobynumber not present
664# getprotoent not present
665# getservbyname not present
666# getservbyport not present
667# getservent not present
668EOM
669 exit
670} }
671getsockname STDIN ; # OP_GETSOCKNAME
672getpeername STDIN ; # OP_GETPEERNAME
673gethostbyname 1 ; # OP_GHBYNAME
674gethostbyaddr 1,2; # OP_GHBYADDR
675gethostent ; # OP_GHOSTENT
676getnetbyname 1 ; # OP_GNBYNAME
677getnetbyaddr 1,2 ; # OP_GNBYADDR
678getnetent ; # OP_GNETENT
679getprotobyname 1; # OP_GPBYNAME
680getprotobynumber 1; # OP_GPBYNUMBER
681getprotoent ; # OP_GPROTOENT
682getservbyname 1,2; # OP_GSBYNAME
683getservbyport 1,2; # OP_GSBYPORT
684getservent ; # OP_GSERVENT
0453d815 685
4438c4b7 686no warnings 'void' ;
0453d815
PM
687getsockname STDIN ; # OP_GETSOCKNAME
688getpeername STDIN ; # OP_GETPEERNAME
689gethostbyname 1 ; # OP_GHBYNAME
690gethostbyaddr 1,2; # OP_GHBYADDR
691gethostent ; # OP_GHOSTENT
692getnetbyname 1 ; # OP_GNBYNAME
693getnetbyaddr 1,2 ; # OP_GNBYADDR
694getnetent ; # OP_GNETENT
695getprotobyname 1; # OP_GPBYNAME
696getprotobynumber 1; # OP_GPBYNUMBER
697getprotoent ; # OP_GPROTOENT
698getservbyname 1,2; # OP_GSBYNAME
699getservbyport 1,2; # OP_GSBYPORT
700getservent ; # OP_GSERVENT
dfe13c55
GS
701INIT {
702 # some functions may not be there, so we exit without running
703 exit;
704}
599cee73
PM
705EXPECT
706Useless use of getsockname in void context at - line 24.
707Useless use of getpeername in void context at - line 25.
708Useless use of gethostbyname in void context at - line 26.
709Useless use of gethostbyaddr in void context at - line 27.
710Useless use of gethostent in void context at - line 28.
711Useless use of getnetbyname in void context at - line 29.
712Useless use of getnetbyaddr in void context at - line 30.
713Useless use of getnetent in void context at - line 31.
714Useless use of getprotobyname in void context at - line 32.
715Useless use of getprotobynumber in void context at - line 33.
716Useless use of getprotoent in void context at - line 34.
717Useless use of getservbyname in void context at - line 35.
718Useless use of getservbyport in void context at - line 36.
719Useless use of getservent in void context at - line 37.
720########
721# op.c
4438c4b7 722use warnings 'void' ;
599cee73
PM
723*a ; # OP_RV2GV
724$a ; # OP_RV2SV
725@a ; # OP_RV2AV
726%a ; # OP_RV2HV
4438c4b7 727no warnings 'void' ;
0453d815
PM
728*a ; # OP_RV2GV
729$a ; # OP_RV2SV
730@a ; # OP_RV2AV
731%a ; # OP_RV2HV
599cee73
PM
732EXPECT
733Useless use of a variable in void context at - line 3.
734Useless use of a variable in void context at - line 4.
735Useless use of a variable in void context at - line 5.
736Useless use of a variable in void context at - line 6.
737########
738# op.c
4438c4b7 739use warnings 'void' ;
599cee73
PM
740"abc"; # OP_CONST
7417 ; # OP_CONST
86f9315f
RD
742"x" . "y"; # optimized to OP_CONST
7432 + 2; # optimized to OP_CONST
e7fec78e 744use constant U => undef;
fa01e093 745U;
919f76a3 746qq/" \n/;
fa01e093 7475 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT
e7fec78e 748print "boo\n" if U; # test OPpCONST_SHORTCIRCUIT
1b268608 749if($foo){}elsif(""){} # test OPpCONST_SHORTCIRCUIT
4438c4b7 750no warnings 'void' ;
0453d815
PM
751"abc"; # OP_CONST
7527 ; # OP_CONST
86f9315f
RD
753"x" . "y"; # optimized to OP_CONST
7542 + 2; # optimized to OP_CONST
599cee73 755EXPECT
919f76a3 756Useless use of a constant ("abc") in void context at - line 3.
86f9315f 757Useless use of a constant (7) in void context at - line 4.
919f76a3 758Useless use of a constant ("xy") in void context at - line 5.
86f9315f 759Useless use of a constant (4) in void context at - line 6.
fa01e093 760Useless use of a constant (undef) in void context at - line 8.
919f76a3 761Useless use of a constant ("\"\t\n") in void context at - line 9.
599cee73
PM
762########
763# op.c
34ee6772
BF
764use utf8;
765use open qw( :utf8 :std );
766use warnings 'void' ;
767"àḆc"; # OP_CONST
768"Ẋ" . "ƴ"; # optimized to OP_CONST
769FOO; # Bareword optimized to OP_CONST
770use constant ů => undef;
771ů;
7725 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT
773print "boo\n" if ů; # test OPpCONST_SHORTCIRCUIT
774no warnings 'void' ;
775"àḆc"; # OP_CONST
776"Ẋ" . "ƴ"; # optimized to OP_CONST
777EXPECT
919f76a3
RGS
778Useless use of a constant ("\340\x{1e06}c") in void context at - line 5.
779Useless use of a constant ("\x{1e8a}\x{1b4}") in void context at - line 6.
780Useless use of a constant ("\x{ff26}\x{ff2f}\x{ff2f}") in void context at - line 7.
34ee6772
BF
781Useless use of a constant (undef) in void context at - line 9.
782########
783# op.c
7f01dc7a 784#
e476b1b5 785use warnings 'misc' ;
b08e453b 786my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;my $d = 'test';
599cee73 787@a =~ /abc/ ;
c6771ab6
FC
788@a2 =~ s/a/b/ ;
789@a3 =~ tr/a/b/ ;
599cee73
PM
790@$b =~ /abc/ ;
791@$b =~ s/a/b/ ;
792@$b =~ tr/a/b/ ;
793%a =~ /abc/ ;
c6771ab6
FC
794%a2 =~ s/a/b/ ;
795%a3 =~ tr/a/b/ ;
599cee73
PM
796%$c =~ /abc/ ;
797%$c =~ s/a/b/ ;
798%$c =~ tr/a/b/ ;
b08e453b 799$d =~ tr/a/b/d ;
c6771ab6 800$d2 =~ tr/a/bc/;
b8c388a9 801$d3 =~ tr//b/c;
0453d815 802{
e476b1b5 803no warnings 'misc' ;
b08e453b 804my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; my $d = 'test';
0453d815
PM
805@a =~ /abc/ ;
806@a =~ s/a/b/ ;
807@a =~ tr/a/b/ ;
808@$b =~ /abc/ ;
809@$b =~ s/a/b/ ;
810@$b =~ tr/a/b/ ;
811%a =~ /abc/ ;
812%a =~ s/a/b/ ;
813%a =~ tr/a/b/ ;
814%$c =~ /abc/ ;
815%$c =~ s/a/b/ ;
816%$c =~ tr/a/b/ ;
b08e453b
RB
817$d =~ tr/a/b/d ;
818$d =~ tr/a/bc/ ;
b8c388a9 819$d =~ tr//b/c;
0453d815 820}
599cee73 821EXPECT
c6771ab6
FC
822Applying pattern match (m//) to @a will act on scalar(@a) at - line 5.
823Applying substitution (s///) to @a2 will act on scalar(@a2) at - line 6.
824Applying transliteration (tr///) to @a3 will act on scalar(@a3) at - line 7.
42d38218
MS
825Applying pattern match (m//) to @array will act on scalar(@array) at - line 8.
826Applying substitution (s///) to @array will act on scalar(@array) at - line 9.
f1612b5c 827Applying transliteration (tr///) to @array will act on scalar(@array) at - line 10.
c6771ab6
FC
828Applying pattern match (m//) to %a will act on scalar(%a) at - line 11.
829Applying substitution (s///) to %a2 will act on scalar(%a2) at - line 12.
830Applying transliteration (tr///) to %a3 will act on scalar(%a3) at - line 13.
42d38218
MS
831Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 14.
832Applying substitution (s///) to %hash will act on scalar(%hash) at - line 15.
f1612b5c 833Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 16.
b08e453b
RB
834Useless use of /d modifier in transliteration operator at - line 17.
835Replacement list is longer than search list at - line 18.
c6771ab6 836Can't modify array dereference in substitution (s///) at - line 6, near "s/a/b/ ;"
b8c388a9 837BEGIN not safe after errors--compilation aborted at - line 21.
599cee73
PM
838########
839# op.c
8473848f 840use warnings 'parenthesis' ;
599cee73 841my $a, $b = (1,2);
8473848f 842my @foo,%bar, $quux; # there's a TAB here
bac662ee 843my $x, $y or print;
8473848f 844no warnings 'parenthesis' ;
0453d815 845my $c, $d = (1,2);
599cee73 846EXPECT
df5b6949 847Parentheses missing around "my" list at - line 3.
8473848f 848Parentheses missing around "my" list at - line 4.
599cee73
PM
849########
850# op.c
8473848f
RGS
851use warnings 'parenthesis' ;
852our $a, $b = (1,2);
853no warnings 'parenthesis' ;
854our $c, $d = (1,2);
855EXPECT
856Parentheses missing around "our" list at - line 3.
857########
858# op.c
859use warnings 'parenthesis' ;
599cee73 860local $a, $b = (1,2);
8473848f
RGS
861local *f, *g;
862no warnings 'parenthesis' ;
0453d815 863local $c, $d = (1,2);
599cee73 864EXPECT
df5b6949 865Parentheses missing around "local" list at - line 3.
8473848f 866Parentheses missing around "local" list at - line 4.
599cee73
PM
867########
868# op.c
e476b1b5 869use warnings 'bareword' ;
599cee73 870print (ABC || 1) ;
e476b1b5 871no warnings 'bareword' ;
0453d815 872print (ABC || 1) ;
599cee73 873EXPECT
34d09196 874Bareword found in conditional at - line 3.
599cee73
PM
875########
876--FILE-- abc
877
878--FILE--
879# op.c
e476b1b5 880use warnings 'misc' ;
599cee73
PM
881open FH, "<abc" ;
882$x = 1 if $x = <FH> ;
502e5101
NC
883$x = 1 if $x
884 = <FH> ;
e476b1b5 885no warnings 'misc' ;
0453d815 886$x = 1 if $x = <FH> ;
502e5101
NC
887$x = 1 if $x
888 = <FH> ;
599cee73
PM
889EXPECT
890Value of <HANDLE> construct can be "0"; test with defined() at - line 4.
502e5101 891Value of <HANDLE> construct can be "0"; test with defined() at - line 5.
599cee73
PM
892########
893# op.c
e476b1b5 894use warnings 'misc' ;
599cee73
PM
895opendir FH, "." ;
896$x = 1 if $x = readdir FH ;
502e5101
NC
897$x = 1 if $x
898 = readdir FH ;
e476b1b5 899no warnings 'misc' ;
0453d815 900$x = 1 if $x = readdir FH ;
502e5101
NC
901$x = 1 if $x
902 = readdir FH ;
599cee73
PM
903closedir FH ;
904EXPECT
905Value of readdir() operator can be "0"; test with defined() at - line 4.
502e5101 906Value of readdir() operator can be "0"; test with defined() at - line 5.
599cee73
PM
907########
908# op.c
e476b1b5 909use warnings 'misc' ;
599cee73 910$x = 1 if $x = <*> ;
502e5101
NC
911$x = 1 if $x
912 = <*> ;
e476b1b5 913no warnings 'misc' ;
0453d815 914$x = 1 if $x = <*> ;
502e5101
NC
915$x = 1 if $x
916 = <*> ;
599cee73
PM
917EXPECT
918Value of glob construct can be "0"; test with defined() at - line 3.
502e5101 919Value of glob construct can be "0"; test with defined() at - line 4.
599cee73
PM
920########
921# op.c
e476b1b5 922use warnings 'misc' ;
599cee73
PM
923%a = (1,2,3,4) ;
924$x = 1 if $x = each %a ;
e476b1b5 925no warnings 'misc' ;
0453d815 926$x = 1 if $x = each %a ;
599cee73
PM
927EXPECT
928Value of each() operator can be "0"; test with defined() at - line 4.
929########
930# op.c
e476b1b5 931use warnings 'misc' ;
599cee73 932$x = 1 while $x = <*> and 0 ;
e476b1b5 933no warnings 'misc' ;
0453d815 934$x = 1 while $x = <*> and 0 ;
599cee73
PM
935EXPECT
936Value of glob construct can be "0"; test with defined() at - line 3.
937########
938# op.c
e476b1b5 939use warnings 'misc' ;
599cee73
PM
940opendir FH, "." ;
941$x = 1 while $x = readdir FH and 0 ;
e476b1b5 942no warnings 'misc' ;
0453d815 943$x = 1 while $x = readdir FH and 0 ;
599cee73
PM
944closedir FH ;
945EXPECT
946Value of readdir() operator can be "0"; test with defined() at - line 4.
947########
948# op.c
59e10468
RGS
949use warnings 'misc';
950open FH, "<abc";
59e10468
RGS
951($_ = <FH>) // ($_ = 1);
952opendir DH, ".";
59e10468 953%a = (1,2,3,4) ;
59e10468
RGS
954EXPECT
955########
956# op.c
4438c4b7 957use warnings 'redefine' ;
599cee73
PM
958sub fred {}
959sub fred {}
2d4e1700
NC
960sub fred { # warning should be for this line
961}
4438c4b7 962no warnings 'redefine' ;
0453d815 963sub fred {}
2d4e1700
NC
964sub fred {
965}
599cee73
PM
966EXPECT
967Subroutine fred redefined at - line 4.
2d4e1700 968Subroutine fred redefined at - line 5.
599cee73
PM
969########
970# op.c
4438c4b7 971use warnings 'redefine' ;
599cee73
PM
972sub fred () { 1 }
973sub fred () { 1 }
4438c4b7 974no warnings 'redefine' ;
0453d815 975sub fred () { 1 }
599cee73
PM
976EXPECT
977Constant subroutine fred redefined at - line 4.
978########
979# op.c
efcf35c4
FC
980sub fred () { 1 }
981sub fred () { 2 }
982EXPECT
983Constant subroutine fred redefined at - line 3.
984########
985# op.c
986sub fred () { 1 }
987*fred = sub () { 2 };
988EXPECT
989Constant subroutine main::fred redefined at - line 3.
990########
991# op.c
ee0832ce
FC
992use feature "lexical_subs", "state";
993my sub fred () { 1 }
994sub fred { 2 };
995my sub george { 1 }
996sub george () { 2 } # should *not* produce redef warnings by default
997state sub phred () { 1 }
998sub phred { 2 };
999state sub jorge { 1 }
1000sub jorge () { 2 } # should *not* produce redef warnings by default
1001EXPECT
64fbf0dd 1002The lexical_subs feature is experimental at - line 3.
ee0832ce
FC
1003Prototype mismatch: sub fred () vs none at - line 4.
1004Constant subroutine fred redefined at - line 4.
64fbf0dd 1005The lexical_subs feature is experimental at - line 5.
ee0832ce 1006Prototype mismatch: sub george: none vs () at - line 6.
64fbf0dd 1007The lexical_subs feature is experimental at - line 7.
ee0832ce
FC
1008Prototype mismatch: sub phred () vs none at - line 8.
1009Constant subroutine phred redefined at - line 8.
64fbf0dd 1010The lexical_subs feature is experimental at - line 9.
ee0832ce
FC
1011Prototype mismatch: sub jorge: none vs () at - line 10.
1012########
1013# op.c
036b4402
GS
1014no warnings 'redefine' ;
1015sub fred () { 1 }
1016sub fred () { 2 }
1017EXPECT
036b4402
GS
1018########
1019# op.c
1020no warnings 'redefine' ;
1021sub fred () { 1 }
1022*fred = sub () { 2 };
1023EXPECT
036b4402
GS
1024########
1025# op.c
4438c4b7 1026use warnings 'redefine' ;
599cee73
PM
1027format FRED =
1028.
1029format FRED =
1030.
4438c4b7 1031no warnings 'redefine' ;
0453d815
PM
1032format FRED =
1033.
599cee73
PM
1034EXPECT
1035Format FRED redefined at - line 5.
1036########
5b3c80aa 1037# op.c [Perl_ck_fun]
0953b66b
FC
1038$fred = [];
1039push $fred;
1040pop $fred;
1041shift $fred;
1042unshift $fred;
1043splice $fred;
d401967c 1044no warnings 'experimental::autoderef' ;
0953b66b
FC
1045push $fred;
1046pop $fred;
1047shift $fred;
1048unshift $fred;
1049splice $fred;
1050EXPECT
1051push on reference is experimental at - line 3.
1052pop on reference is experimental at - line 4.
1053shift on reference is experimental at - line 5.
1054unshift on reference is experimental at - line 6.
1055splice on reference is experimental at - line 7.
1056########
1057# op.c
573d2b1a 1058use warnings 'exec' ;
dfe13c55 1059exec "$^X -e 1" ;
599cee73
PM
1060my $a
1061EXPECT
7b903762 1062Statement unlikely to be reached at - line 4.
cc507455 1063 (Maybe you meant system() when you said exec()?)
69794302 1064########
ea31ed66 1065# op.c, no warning if exec isn't a statement.
573d2b1a 1066use warnings 'exec' ;
ea31ed66
GG
1067$a || exec "$^X -e 1" ;
1068my $a
1069EXPECT
1070########
69794302 1071# op.c
b880f709
NC
1072defined(@a);
1073EXPECT
1074defined(@array) is deprecated at - line 2.
1075 (Maybe you should just omit the defined()?)
1076########
1077# op.c
69794302
MJD
1078my @a; defined(@a);
1079EXPECT
d1d15184 1080defined(@array) is deprecated at - line 2.
cc507455 1081 (Maybe you should just omit the defined()?)
69794302
MJD
1082########
1083# op.c
69794302
MJD
1084defined(@a = (1,2,3));
1085EXPECT
d1d15184 1086defined(@array) is deprecated at - line 2.
cc507455 1087 (Maybe you should just omit the defined()?)
69794302
MJD
1088########
1089# op.c
b880f709
NC
1090defined(%h);
1091EXPECT
1092defined(%hash) is deprecated at - line 2.
1093 (Maybe you should just omit the defined()?)
1094########
1095# op.c
69794302
MJD
1096my %h; defined(%h);
1097EXPECT
d1d15184 1098defined(%hash) is deprecated at - line 2.
cc507455 1099 (Maybe you should just omit the defined()?)
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
1146use utf8;
1147use open qw( :utf8 :std );
1148use warnings;
b54d603d
PM
1149BEGIN { $::{"foo"} = "\@\$\0L\351on" }
1150BEGIN { eval "sub foo (@\$\0L\x{c3}\x{a9}on) {}"; }
dab1c735 1151EXPECT
b54d603d
PM
1152Prototype after '@' for main::foo : @$\x{0}L... at (eval 1) line 1.
1153Illegal character in prototype for main::foo : @$\x{0}L... at (eval 1) line 1.
dab1c735
BF
1154########
1155# op.c
1156use utf8;
1157use open qw( :utf8 :std );
1158use warnings;
b54d603d 1159BEGIN { eval "sub foo (@\0) {}"; }
dab1c735 1160EXPECT
b54d603d
PM
1161Prototype after '@' for main::foo : @\0 at (eval 1) line 1.
1162Illegal character in prototype for main::foo : @\0 at (eval 1) line 1.
97eb901d
BF
1163########
1164# op.c
1165use warnings;
b54d603d 1166eval "sub foo (@\xAB) {}";
97eb901d 1167EXPECT
b54d603d
PM
1168Prototype after '@' for main::foo : @\x{ab} at (eval 1) line 1.
1169Illegal character in prototype for main::foo : @\x{ab} at (eval 1) line 1.
97eb901d
BF
1170########
1171# op.c
1172use utf8;
1173use open qw( :utf8 :std );
1174use warnings;
b54d603d 1175BEGIN { eval "sub foo (@\x{30cb}) {}"; }
97eb901d 1176EXPECT
b54d603d
PM
1177Prototype after '@' for main::foo : @\x{30cb} at (eval 1) line 1.
1178Illegal character in prototype for main::foo : @\x{30cb} at (eval 1) line 1.
dab1c735
BF
1179########
1180# op.c
1181use utf8;
1182use open qw( :utf8 :std );
1183use warnings;
1184BEGIN { $::{"foo"} = "\x{30cb}" }
1185BEGIN { eval "sub foo {}"; }
1186EXPECT
1187Prototype mismatch: sub main::foo (ニ) vs none at (eval 1) line 1.
1188########
1189# op.c
0453d815
PM
1190$^W = 0 ;
1191sub fred() ;
1192sub fred($) {}
1193{
e476b1b5 1194 no warnings 'prototype' ;
0453d815
PM
1195 sub Fred() ;
1196 sub Fred($) {}
e476b1b5 1197 use warnings 'prototype' ;
0453d815
PM
1198 sub freD() ;
1199 sub freD($) {}
1200}
1201sub FRED() ;
1202sub FRED($) {}
1203EXPECT
1204Prototype mismatch: sub main::fred () vs ($) at - line 4.
1205Prototype mismatch: sub main::freD () vs ($) at - line 11.
1206Prototype mismatch: sub main::FRED () vs ($) at - line 14.
eb6e2d6f 1207########
271c8bde
FC
1208# op.c [S_simplify_sort]
1209# [perl #86136]
1210my @tests = split /^/, '
1211 sort {$a <=> $b} @a;
1212 sort {$a cmp $b} @a;
1213 { use integer; sort {$a <=> $b} @a}
1214 sort {$b <=> $a} @a;
1215 sort {$b cmp $a} @a;
1216 { use integer; sort {$b <=> $a} @a}
1217';
1218for my $pragma ('use warnings "syntax";', '') {
1219 for my $vars ('', 'my $a;', 'my $b;', 'my ($a,$b);') {
1220 for my $inner_stmt ('', 'print;', 'func();') {
1221 eval "#line " . ++$line . "01 -\n$pragma\n$vars"
1222 . join "", map s/sort \{\K/$inner_stmt/r, @tests;
1223 $@ and die;
1224 }
1225 }
1226}
1227sub func{}
1228use warnings 'syntax';
1229my $a;
1230# These used to be errors!
1231sort { ; } $a <=> $b;
1232sort { ; } $a, "<=>";
1233sort { ; } $a, $cmp;
1234sort $a, $b if $cmpany_name;
1235sort if $a + $cmp;
1236sort @t; $a + $cmp;
1237EXPECT
1238"my $a" used in sort comparison at - line 403.
1239"my $a" used in sort comparison at - line 404.
1240"my $a" used in sort comparison at - line 405.
1241"my $a" used in sort comparison at - line 406.
1242"my $a" used in sort comparison at - line 407.
1243"my $a" used in sort comparison at - line 408.
1244"my $a" used in sort comparison at - line 503.
1245"my $a" used in sort comparison at - line 504.
1246"my $a" used in sort comparison at - line 505.
1247"my $a" used in sort comparison at - line 506.
1248"my $a" used in sort comparison at - line 507.
1249"my $a" used in sort comparison at - line 508.
1250"my $a" used in sort comparison at - line 603.
1251"my $a" used in sort comparison at - line 604.
1252"my $a" used in sort comparison at - line 605.
1253"my $a" used in sort comparison at - line 606.
1254"my $a" used in sort comparison at - line 607.
1255"my $a" used in sort comparison at - line 608.
1256"my $b" used in sort comparison at - line 703.
1257"my $b" used in sort comparison at - line 704.
1258"my $b" used in sort comparison at - line 705.
1259"my $b" used in sort comparison at - line 706.
1260"my $b" used in sort comparison at - line 707.
1261"my $b" used in sort comparison at - line 708.
1262"my $b" used in sort comparison at - line 803.
1263"my $b" used in sort comparison at - line 804.
1264"my $b" used in sort comparison at - line 805.
1265"my $b" used in sort comparison at - line 806.
1266"my $b" used in sort comparison at - line 807.
1267"my $b" used in sort comparison at - line 808.
1268"my $b" used in sort comparison at - line 903.
1269"my $b" used in sort comparison at - line 904.
1270"my $b" used in sort comparison at - line 905.
1271"my $b" used in sort comparison at - line 906.
1272"my $b" used in sort comparison at - line 907.
1273"my $b" used in sort comparison at - line 908.
1274"my $a" used in sort comparison at - line 1003.
1275"my $b" used in sort comparison at - line 1003.
1276"my $a" used in sort comparison at - line 1004.
1277"my $b" used in sort comparison at - line 1004.
1278"my $a" used in sort comparison at - line 1005.
1279"my $b" used in sort comparison at - line 1005.
1280"my $b" used in sort comparison at - line 1006.
1281"my $a" used in sort comparison at - line 1006.
1282"my $b" used in sort comparison at - line 1007.
1283"my $a" used in sort comparison at - line 1007.
1284"my $b" used in sort comparison at - line 1008.
1285"my $a" used in sort comparison at - line 1008.
1286"my $a" used in sort comparison at - line 1103.
1287"my $b" used in sort comparison at - line 1103.
1288"my $a" used in sort comparison at - line 1104.
1289"my $b" used in sort comparison at - line 1104.
1290"my $a" used in sort comparison at - line 1105.
1291"my $b" used in sort comparison at - line 1105.
1292"my $b" used in sort comparison at - line 1106.
1293"my $a" used in sort comparison at - line 1106.
1294"my $b" used in sort comparison at - line 1107.
1295"my $a" used in sort comparison at - line 1107.
1296"my $b" used in sort comparison at - line 1108.
1297"my $a" used in sort comparison at - line 1108.
1298"my $a" used in sort comparison at - line 1203.
1299"my $b" used in sort comparison at - line 1203.
1300"my $a" used in sort comparison at - line 1204.
1301"my $b" used in sort comparison at - line 1204.
1302"my $a" used in sort comparison at - line 1205.
1303"my $b" used in sort comparison at - line 1205.
1304"my $b" used in sort comparison at - line 1206.
1305"my $a" used in sort comparison at - line 1206.
1306"my $b" used in sort comparison at - line 1207.
1307"my $a" used in sort comparison at - line 1207.
1308"my $b" used in sort comparison at - line 1208.
1309"my $a" used in sort comparison at - line 1208.
1310########
a2e39214
FC
1311# op.c [S_simplify_sort]
1312use warnings 'syntax'; use 5.01;
1313state $a;
1314sort { $a <=> $b } ();
1315EXPECT
1316"state $a" used in sort comparison at - line 4.
1317########
89474f50
FC
1318# op.c [Perl_ck_cmp]
1319use warnings 'syntax' ;
1320no warnings 'deprecated';
1321@a = $[ < 5;
1322@a = $[ > 5;
1323@a = $[ <= 5;
1324@a = $[ >= 5;
1325@a = 42 < $[;
1326@a = 42 > $[;
1327@a = 42 <= $[;
1328@a = 42 >= $[;
1329use integer;
1330@a = $[ < 5;
1331@a = $[ > 5;
1332@a = $[ <= 5;
1333@a = $[ >= 5;
1334@a = 42 < $[;
1335@a = 42 > $[;
1336@a = 42 <= $[;
1337@a = 42 >= $[;
7c2b3c78
FC
1338no integer;
1339@a = $[ < $5;
1340@a = $[ > $5;
1341@a = $[ <= $5;
1342@a = $[ >= $5;
1343@a = $42 < $[;
1344@a = $42 > $[;
1345@a = $42 <= $[;
1346@a = $42 >= $[;
1347use integer;
1348@a = $[ < $5;
1349@a = $[ > $5;
1350@a = $[ <= $5;
1351@a = $[ >= $5;
1352@a = $42 < $[;
1353@a = $42 > $[;
1354@a = $42 <= $[;
1355@a = $42 >= $[;
89474f50
FC
1356EXPECT
1357$[ used in numeric lt (<) (did you mean $] ?) at - line 4.
1358$[ used in numeric gt (>) (did you mean $] ?) at - line 5.
1359$[ used in numeric le (<=) (did you mean $] ?) at - line 6.
1360$[ used in numeric ge (>=) (did you mean $] ?) at - line 7.
1361$[ used in numeric lt (<) (did you mean $] ?) at - line 8.
1362$[ used in numeric gt (>) (did you mean $] ?) at - line 9.
1363$[ used in numeric le (<=) (did you mean $] ?) at - line 10.
1364$[ used in numeric ge (>=) (did you mean $] ?) at - line 11.
1365$[ used in numeric lt (<) (did you mean $] ?) at - line 13.
1366$[ used in numeric gt (>) (did you mean $] ?) at - line 14.
1367$[ used in numeric le (<=) (did you mean $] ?) at - line 15.
1368$[ used in numeric ge (>=) (did you mean $] ?) at - line 16.
1369$[ used in numeric lt (<) (did you mean $] ?) at - line 17.
1370$[ used in numeric gt (>) (did you mean $] ?) at - line 18.
1371$[ used in numeric le (<=) (did you mean $] ?) at - line 19.
1372$[ used in numeric ge (>=) (did you mean $] ?) at - line 20.
1373########
0953b66b
FC
1374# op.c [Perl_ck_each]
1375$fred = {};
1376keys $fred;
1377values $fred;
1378each $fred;
d401967c 1379no warnings 'experimental::autoderef' ;
0953b66b
FC
1380keys $fred;
1381values $fred;
1382each $fred;
1383EXPECT
1384keys on reference is experimental at - line 3.
1385values on reference is experimental at - line 4.
1386each on reference is experimental at - line 5.
1387########
e508c8a4
MH
1388# op.c [Perl_ck_length]
1389use warnings 'syntax' ;
1390length(@a);
579333ee
FC
1391length(%b);
1392length(@$c);
1393length(%$d);
e508c8a4 1394length($a);
9710ad41 1395length(my %h);
579333ee 1396length(my @g);
e508c8a4 1397EXPECT
579333ee
FC
1398length() used on @a (did you mean "scalar(@a)"?) at - line 3.
1399length() used on %b (did you mean "scalar(keys %b)"?) at - line 4.
e508c8a4
MH
1400length() used on @array (did you mean "scalar(@array)"?) at - line 5.
1401length() used on %hash (did you mean "scalar(keys %hash)"?) at - line 6.
579333ee
FC
1402length() used on %h (did you mean "scalar(keys %h)"?) at - line 8.
1403length() used on @g (did you mean "scalar(@g)"?) at - line 9.
e508c8a4 1404########
eb6e2d6f
GS
1405# op.c
1406use warnings 'syntax' ;
1407join /---/, 'x', 'y', 'z';
1408EXPECT
1409/---/ should probably be written as "---" at - line 3.
767a6a26 1410########
ce16c625
BF
1411# op.c
1412use utf8;
1413use open qw( :utf8 :std );
1414use warnings 'syntax' ;
1415join /~~~/, 'x', 'y', 'z';
1416EXPECT
1417/~~~/ should probably be written as "~~~" at - line 5.
1418########
767a6a26 1419# op.c [Perl_peep]
e476b1b5 1420use warnings 'prototype' ;
767a6a26
PM
1421fred() ;
1422sub fred ($$) {}
e476b1b5 1423no warnings 'prototype' ;
767a6a26
PM
1424joe() ;
1425sub joe ($$) {}
1426EXPECT
1427main::fred() called too early to check prototype at - line 3.
ddda08b7
GS
1428########
1429# op.c [Perl_newATTRSUB]
1430--FILE-- abc.pm
1431use warnings 'void' ;
1432BEGIN { $| = 1; print "in begin\n"; }
1433CHECK { print "in check\n"; }
1434INIT { print "in init\n"; }
1435END { print "in end\n"; }
1436print "in mainline\n";
14371;
1438--FILE--
1439use abc;
1440delete $INC{"abc.pm"};
1441require abc;
1442do "abc.pm";
1443EXPECT
1444in begin
1445in mainline
1446in check
1447in init
1448in begin
1449Too late to run CHECK block at abc.pm line 3.
1450Too late to run INIT block at abc.pm line 4.
1451in mainline
1452in begin
1453Too late to run CHECK block at abc.pm line 3.
1454Too late to run INIT block at abc.pm line 4.
1455in mainline
1456in end
1457in end
1458in end
1459########
1460# op.c [Perl_newATTRSUB]
1461--FILE-- abc.pm
1462no warnings 'void' ;
1463BEGIN { $| = 1; print "in begin\n"; }
1464CHECK { print "in check\n"; }
1465INIT { print "in init\n"; }
1466END { print "in end\n"; }
1467print "in mainline\n";
14681;
1469--FILE--
1470require abc;
1471do "abc.pm";
1472EXPECT
1473in begin
1474in mainline
1475in begin
1476in mainline
1477in end
1478in end
936edb8b
RH
1479########
1480# op.c
1481my @x;
f87c3213 1482use warnings 'syntax' ;
936edb8b
RH
1483push(@x);
1484unshift(@x);
f87c3213 1485no warnings 'syntax' ;
936edb8b
RH
1486push(@x);
1487unshift(@x);
1488EXPECT
de4864e4
JH
1489Useless use of push with no values at - line 4.
1490Useless use of unshift with no values at - line 5.
a27978d3
AMS
1491########
1492# op.c
f34840d8
MJD
1493# 20020401 mjd@plover.com at suggestion of jfriedl@yahoo.com
1494use warnings 'regexp';
1495split /blah/g, "blah";
1496no warnings 'regexp';
1497split /blah/g, "blah";
1498EXPECT
1499Use of /g modifier is meaningless in split at - line 4.
276b2a0c
RGS
1500########
1501# op.c
1502use warnings 'precedence';
1503$a = $b & $c == $d;
1504$a = $b ^ $c != $d;
1505$a = $b | $c > $d;
1506$a = $b < $c & $d;
1507$a = $b >= $c ^ $d;
1508$a = $b <= $c | $d;
1509$a = $b <=> $c & $d;
2b84528b 1510$a &= $b == $c; $a |= $b == $c; $a ^= $b == $c; # shouldn't warn
276b2a0c
RGS
1511no warnings 'precedence';
1512$a = $b & $c == $d;
1513$a = $b ^ $c != $d;
1514$a = $b | $c > $d;
1515$a = $b < $c & $d;
1516$a = $b >= $c ^ $d;
1517$a = $b <= $c | $d;
1518$a = $b <=> $c & $d;
1519EXPECT
1520Possible precedence problem on bitwise & operator at - line 3.
1521Possible precedence problem on bitwise ^ operator at - line 4.
1522Possible precedence problem on bitwise | operator at - line 5.
1523Possible precedence problem on bitwise & operator at - line 6.
1524Possible precedence problem on bitwise ^ operator at - line 7.
1525Possible precedence problem on bitwise | operator at - line 8.
1526Possible precedence problem on bitwise & operator at - line 9.
1527########
1528# op.c
1529use integer;
1530use warnings 'precedence';
1531$a = $b & $c == $d;
1532$a = $b ^ $c != $d;
1533$a = $b | $c > $d;
1534$a = $b < $c & $d;
1535$a = $b >= $c ^ $d;
1536$a = $b <= $c | $d;
1537$a = $b <=> $c & $d;
1538no warnings 'precedence';
1539$a = $b & $c == $d;
1540$a = $b ^ $c != $d;
1541$a = $b | $c > $d;
1542$a = $b < $c & $d;
1543$a = $b >= $c ^ $d;
1544$a = $b <= $c | $d;
1545$a = $b <=> $c & $d;
1546EXPECT
1547Possible precedence problem on bitwise & operator at - line 4.
1548Possible precedence problem on bitwise ^ operator at - line 5.
1549Possible precedence problem on bitwise | operator at - line 6.
1550Possible precedence problem on bitwise & operator at - line 7.
1551Possible precedence problem on bitwise ^ operator at - line 8.
1552Possible precedence problem on bitwise | operator at - line 9.
1553Possible precedence problem on bitwise & operator at - line 10.
ddeae0f1
DM
1554########
1555# op.c
1556
1557# ok => local() has desired effect;
1558# ignore=> local() silently ignored
1559
1560use warnings 'syntax';
1561
1562local(undef); # OP_UNDEF ignore
1563sub lval : lvalue {};
1564local(lval()); # OP_ENTERSUB
1565local($x **= 1); # OP_POW
1566local($x *= 1); # OP_MULTIPLY
1567local($x /= 1); # OP_DIVIDE
1568local($x %= 1); # OP_MODULO
1569local($x x= 1); # OP_REPEAT
1570local($x += 1); # OP_ADD
1571local($x -= 1); # OP_SUBTRACT
1572local($x .= 1); # OP_CONCAT
1573local($x <<= 1); # OP_LEFT_SHIFT
1574local($x >>= 1); # OP_RIGHT_SHIFT
1575local($x &= 1); # OP_BIT_AND
1576local($x ^= 1); # OP_BIT_XOR
1577local($x |= 1); # OP_BIT_OR
1578{
1579 use integer;
1580 local($x *= 1); # OP_I_MULTIPLY
1581 local($x /= 1); # OP_I_DIVIDE
1582 local($x %= 1); # OP_I_MODULO
1583 local($x += 1); # OP_I_ADD
1584 local($x -= 1); # OP_I_SUBTRACT
1585}
1586local($x?$y:$z) = 1; # OP_COND_EXPR ok
1587# these two are fatal run-time errors instead
1588#local(@$a); # OP_RV2AV ok
1589#local(%$a); # OP_RV2HV ok
1590local(*a); # OP_RV2GV ok
1591local(@a[1,2]); # OP_ASLICE ok
1592local(@a{1,2}); # OP_HSLICE ok
1593local(@a = (1,2)); # OP_AASSIGN
1594local($$x); # OP_RV2SV ok
1595local($#a); # OP_AV2ARYLEN
1596local($x = 1); # OP_SASSIGN
1597local($x &&= 1); # OP_ANDASSIGN
1598local($x ||= 1); # OP_ORASSIGN
1599local($x //= 1); # OP_DORASSIGN
1600local($a[0]); # OP_AELEMFAST ok
1601
1602local(substr($x,0,1)); # OP_SUBSTR
1603local(pos($x)); # OP_POS
1604local(vec($x,0,1)); # OP_VEC
1605local($a[$b]); # OP_AELEM ok
1606local($a{$b}); # OP_HELEM ok
1607
1608no warnings 'syntax';
1609EXPECT
1610Useless localization of subroutine entry at - line 10.
1611Useless localization of exponentiation (**) at - line 11.
1612Useless localization of multiplication (*) at - line 12.
1613Useless localization of division (/) at - line 13.
1614Useless localization of modulus (%) at - line 14.
1615Useless localization of repeat (x) at - line 15.
1616Useless localization of addition (+) at - line 16.
1617Useless localization of subtraction (-) at - line 17.
1618Useless localization of concatenation (.) or string at - line 18.
1619Useless localization of left bitshift (<<) at - line 19.
1620Useless localization of right bitshift (>>) at - line 20.
1621Useless localization of bitwise and (&) at - line 21.
1622Useless localization of bitwise xor (^) at - line 22.
1623Useless localization of bitwise or (|) at - line 23.
1624Useless localization of integer multiplication (*) at - line 26.
1625Useless localization of integer division (/) at - line 27.
1626Useless localization of integer modulus (%) at - line 28.
1627Useless localization of integer addition (+) at - line 29.
1628Useless localization of integer subtraction (-) at - line 30.
1629Useless localization of list assignment at - line 39.
1630Useless localization of array length at - line 41.
1631Useless localization of scalar assignment at - line 42.
1632Useless localization of logical and assignment (&&=) at - line 43.
1633Useless localization of logical or assignment (||=) at - line 44.
1634Useless localization of defined or assignment (//=) at - line 45.
1635Useless localization of substr at - line 48.
1636Useless localization of match position at - line 49.
1637Useless localization of vec at - line 50.
7921d0f2
DM
1638########
1639# op.c
7921d0f2
DM
1640my $x1 if 0;
1641my @x2 if 0;
1642my %x3 if 0;
1643my ($x4) if 0;
1644my ($x5,@x6, %x7) if 0;
16450 && my $z1;
16460 && my (%z2);
1647# these shouldn't warn
1648our $x if 0;
1649our $x unless 0;
1650if (0) { my $w1 }
1651if (my $w2) { $a=1 }
1652if ($a && (my $w3 = 1)) {$a = 2}
1653
1654EXPECT
d1d15184 1655Deprecated use of my() in false conditional at - line 2.
7921d0f2
DM
1656Deprecated use of my() in false conditional at - line 3.
1657Deprecated use of my() in false conditional at - line 4.
1658Deprecated use of my() in false conditional at - line 5.
1659Deprecated use of my() in false conditional at - line 6.
1660Deprecated use of my() in false conditional at - line 7.
1661Deprecated use of my() in false conditional at - line 8.
55b67815
RGS
1662########
1663# op.c
36b2db7e
FC
1664$[ = 1;
1665($[) = 1;
1666use warnings 'deprecated';
1667$[ = 2;
1668($[) = 2;
1669no warnings 'deprecated';
1670$[ = 3;
1671($[) = 3;
1672EXPECT
1673Use of assignment to $[ is deprecated at - line 2.
1674Use of assignment to $[ is deprecated at - line 3.
1675Use of assignment to $[ is deprecated at - line 5.
1676Use of assignment to $[ is deprecated at - line 6.
1677########
1678# op.c
75068674
RGS
1679use warnings 'void';
1680@x = split /y/, "z";
1681$x = split /y/, "z";
1682 split /y/, "z";
1683no warnings 'void';
1684@x = split /y/, "z";
1685$x = split /y/, "z";
1686 split /y/, "z";
1687EXPECT
1688Useless use of split in void context at - line 5.
34ee6772
BF
1689########
1690# op.c
1691use warnings 'redefine' ;
1692use utf8;
1693use open qw( :utf8 :std );
1694sub frèd {}
1695sub frèd {}
1696no warnings 'redefine' ;
1697sub frèd {}
1698EXPECT
1699Subroutine frèd redefined at - line 6.
1700########
1701# op.c
1702use warnings 'redefine' ;
1703use utf8;
1704use open qw( :utf8 :std );
1705sub frèd () { 1 }
1706sub frèd () { 1 }
1707no warnings 'redefine' ;
1708sub frèd () { 1 }
1709EXPECT
1710Constant subroutine frèd redefined at - line 6.
1711########
1712# op.c
34ee6772
BF
1713use utf8;
1714use open qw( :utf8 :std );
1715sub frèd () { 1 }
1716sub frèd () { 2 }
1717EXPECT
efcf35c4 1718Constant subroutine frèd redefined at - line 5.
34ee6772
BF
1719########
1720# op.c
34ee6772
BF
1721use utf8;
1722use open qw( :utf8 :std );
1723sub frèd () { 1 }
1724*frèd = sub () { 2 };
1725EXPECT
efcf35c4 1726Constant subroutine main::frèd redefined at - line 5.
34ee6772
BF
1727########
1728# op.c
1729use warnings 'redefine' ;
1730use utf8;
1731use open qw( :utf8 :std );
1732sub ᚠርƊ {}
1733sub ᚠርƊ {}
1734no warnings 'redefine' ;
1735sub ᚠርƊ {}
1736EXPECT
1737Subroutine ᚠርƊ redefined at - line 6.
1738########
1739# op.c
1740use warnings 'redefine' ;
1741use utf8;
1742use open qw( :utf8 :std );
1743sub ᚠርƊ () { 1 }
1744sub ᚠርƊ () { 1 }
1745no warnings 'redefine' ;
1746sub ᚠርƊ () { 1 }
1747EXPECT
1748Constant subroutine ᚠርƊ redefined at - line 6.
1749########
1750# op.c
34ee6772
BF
1751use utf8;
1752use open qw( :utf8 :std );
1753sub ᚠርƊ () { 1 }
1754sub ᚠርƊ () { 2 }
1755EXPECT
efcf35c4 1756Constant subroutine ᚠርƊ redefined at - line 5.
34ee6772
BF
1757########
1758# op.c
34ee6772
BF
1759use utf8;
1760use open qw( :utf8 :std );
1761sub ᚠርƊ () { 1 }
1762*ᚠርƊ = sub () { 2 };
1763EXPECT
efcf35c4 1764Constant subroutine main::ᚠርƊ redefined at - line 5.
34ee6772 1765########
d787f4a5
NC
1766# OPTION regex
1767sub DynaLoader::dl_error {};
1768use warnings;
1769# We're testing that the warnings report the same line number:
1770eval <<'EOC' or die $@;
1771{
1772 DynaLoader::boot_DynaLoader("DynaLoader");
1773}
1774EOC
1775eval <<'EOC' or die $@;
1776BEGIN {
1777 DynaLoader::boot_DynaLoader("DynaLoader");
1778}
17791
1780EOC
1781EXPECT
1782OPTION regex
1783\ASubroutine DynaLoader::dl_error redefined at \(eval 1\) line 2\.
b5ab070a 1784?(?s).*
d787f4a5
NC
1785Subroutine DynaLoader::dl_error redefined at \(eval 2\) line 2\.
1786########
9da2d046
NT
1787# op.c
1788use warnings;
1789sub do_warn_1 { return $a or $b; }
1790sub do_warn_2 { return $a and $b; }
1791sub do_warn_3 { return $a xor $b; }
1792sub do_warn_4 { die $a or $b; }
1793sub do_warn_5 { die $a and $b; }
1794sub do_warn_6 { die $a xor $b; }
1795sub do_warn_7 { exit $a or $b; }
1796sub do_warn_8 { exit $a and $b; }
1797sub do_warn_9 { exit $a xor $b; }
1798
1799# Since exit is an unary operator, it is even stronger than
1800# || and &&.
1801sub do_warn_10 { exit $a || $b; }
1802sub do_warn_11 { exit $a && $b; }
1803
1804sub do_warn_12 { goto $a or $b; }
1805sub do_warn_13 { goto $a and $b; }
1806sub do_warn_14 { goto $a xor $b; }
1807sub do_warn_15 { next $a or $b while(1); }
1808sub do_warn_16 { next $a and $b while(1); }
1809sub do_warn_17 { next $a xor $b while(1); }
1810sub do_warn_18 { last $a or $b while(1); }
1811sub do_warn_19 { last $a and $b while(1); }
1812sub do_warn_20 { last $a xor $b while(1); }
1813sub do_warn_21 { redo $a or $b while(1); }
1814sub do_warn_22 { redo $a and $b while(1); }
1815sub do_warn_23 { redo $a xor $b while(1); }
1816# These get re-written to "(return/die $a) and $b"
1817sub do_warn_24 { $b if return $a; }
1818sub do_warn_25 { $b if die $a; }
1819EXPECT
1820Possible precedence issue with control flow operator at - line 3.
1821Possible precedence issue with control flow operator at - line 4.
1822Possible precedence issue with control flow operator at - line 5.
1823Possible precedence issue with control flow operator at - line 6.
1824Possible precedence issue with control flow operator at - line 7.
1825Possible precedence issue with control flow operator at - line 8.
1826Possible precedence issue with control flow operator at - line 9.
1827Possible precedence issue with control flow operator at - line 10.
1828Possible precedence issue with control flow operator at - line 11.
1829Possible precedence issue with control flow operator at - line 15.
1830Possible precedence issue with control flow operator at - line 16.
1831Possible precedence issue with control flow operator at - line 18.
1832Possible precedence issue with control flow operator at - line 19.
1833Possible precedence issue with control flow operator at - line 20.
1834Possible precedence issue with control flow operator at - line 21.
1835Possible precedence issue with control flow operator at - line 22.
1836Possible precedence issue with control flow operator at - line 23.
1837Possible precedence issue with control flow operator at - line 24.
1838Possible precedence issue with control flow operator at - line 25.
1839Possible precedence issue with control flow operator at - line 26.
1840Possible precedence issue with control flow operator at - line 27.
1841Possible precedence issue with control flow operator at - line 28.
1842Possible precedence issue with control flow operator at - line 29.
1843Possible precedence issue with control flow operator at - line 31.
1844Possible precedence issue with control flow operator at - line 32.
1845########
1846# op.c
1847# (same as above, except these should not warn)
1848use constant FEATURE => 1;
1849use constant MISSING_FEATURE => 0;
1850
1851sub dont_warn_1 { MISSING_FEATURE and return or dont_warn_3(); }
1852sub dont_warn_2 { FEATURE || return and dont_warn_3(); }
1853sub dont_warn_3 { not FEATURE and return or dont_warn_3(); }
1854sub dont_warn_4 { !MISSING_FEATURE || return and dont_warn_3(); }
1855sub dont_warn_5 { MISSING_FEATURE and die or dont_warn_3(); }
1856sub dont_warn_6 { FEATURE || die and dont_warn_3(); }
1857sub dont_warn_7 { not FEATURE and die or dont_warn_3(); }
1858sub dont_warn_8 { !MISSING_FEATURE || die and dont_warn_3(); }
1859sub dont_warn_9 { MISSING_FEATURE and goto $a or dont_warn_3(); }
1860sub dont_warn_10 { FEATURE || goto $a and dont_warn_3(); }
1861sub dont_warn_11 { not FEATURE and goto $a or dont_warn_3(); }
1862sub dont_warn_12 { !MISSING_FEATURE || goto $a and dont_warn_3(); }
1863
1864sub dont_warn_13 { MISSING_FEATURE and exit $a or dont_warn_3(); }
1865sub dont_warn_14 { FEATURE || exit $a and dont_warn_3(); }
1866sub dont_warn_15 { not FEATURE and exit $a or dont_warn_3(); }
1867sub dont_warn_16 { !MISSING_FEATURE || exit $a and dont_warn_3(); }
1868
1869sub dont_warn_17 { MISSING_FEATURE and next or dont_warn_3() while(1); }
1870sub dont_warn_18 { FEATURE || next and dont_warn_3() while(1); }
1871sub dont_warn_19 { not FEATURE and next or dont_warn_3() while(1); }
1872sub dont_warn_20 { !MISSING_FEATURE || next and dont_warn_3() while(1); }
1873sub dont_warn_21 { MISSING_FEATURE and redo or dont_warn_3() while(1); }
1874sub dont_warn_22 { FEATURE || redo and dont_warn_3() while(1); }
1875sub dont_warn_23 { not FEATURE and redo or dont_warn_3() while(1); }
1876sub dont_warn_24 { !MISSING_FEATURE || redo and dont_warn_3() while(1); }
1877sub dont_warn_25 { MISSING_FEATURE and last or dont_warn_3() while(1); }
1878sub dont_warn_26 { FEATURE || last and dont_warn_3() while(1); }
1879sub dont_warn_27 { not FEATURE and last or dont_warn_3() while(1); }
1880sub dont_warn_28 { !MISSING_FEATURE || last and dont_warn_3() while(1); }
1881
1882# These are weird, but at least not ambiguous.
1883sub dont_warn_29 { return ($a or $b); }
1884sub dont_warn_30 { return ($a and $b); }
1885sub dont_warn_31 { return ($a xor $b); }
1886sub dont_warn_32 { die ($a or $b); }
1887sub dont_warn_33 { die ($a and $b); }
1888sub dont_warn_34 { die ($a xor $b); }
1889sub dont_warn_35 { goto ($a or $b); }
1890sub dont_warn_36 { goto ($a and $b); }
1891sub dont_warn_37 { goto ($a xor $b); }
1892sub dont_warn_38 { next ($a or $b) while(1); }
1893sub dont_warn_39 { next ($a and $b) while(1); }
1894sub dont_warn_40 { next ($a xor $b) while(1); }
1895sub dont_warn_41 { last ($a or $b) while(1); }
1896sub dont_warn_42 { last ($a and $b) while(1); }
1897sub dont_warn_43 { last ($a xor $b) while(1); }
1898sub dont_warn_44 { redo ($a or $b) while(1); }
1899sub dont_warn_45 { redo ($a and $b) while(1); }
1900sub dont_warn_46 { redo ($a xor $b) while(1); }
1901EXPECT
30d9c59b
Z
1902########
1903use feature "signatures";
1904sub aaa { 2 }
1905sub bbb ($a) { 4 }
1906$aaa = sub { 2 };
1907$bbb = sub ($a) { 4 };
1908EXPECT
1909The signatures feature is experimental at - line 3.
1910The signatures feature is experimental at - line 5.
1911########
1912no warnings "experimental::signatures";
1913use feature "signatures";
1914sub aaa { 2 }
1915sub bbb ($a) { 4 }
1916$aaa = sub { 2 };
1917$bbb = sub ($a) { 4 };
1918EXPECT