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