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