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