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