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