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