This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Warn by default for constant my sub redefinition
[perl5.git] / t / lib / warnings / op
1   op.c          AOK
2
3      Found = in conditional, should be ==
4         1 if $a = 1 ;
5
6      Useless use of time in void context
7      Useless use of a variable in void context
8      Useless use of a constant in void context
9         time ;
10         $a ;
11         "abc"
12
13      Useless use of sort in scalar context
14         my $x = sort (2,1,3);
15
16      Applying %s to %s will act on scalar(%s)
17         my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
18         @a =~ /abc/ ;
19         @a =~ s/a/b/ ;
20         @a =~ tr/a/b/ ;
21         @$b =~ /abc/ ;
22         @$b =~ s/a/b/ ;
23         @$b =~ tr/a/b/ ;
24         %a =~ /abc/ ;
25         %a =~ s/a/b/ ;
26         %a =~ tr/a/b/ ;
27         %$c =~ /abc/ ;
28         %$c =~ s/a/b/ ;
29         %$c =~ tr/a/b/ ;
30
31
32      Parentheses missing around "my" list at -e line 1.
33        my $a, $b = (1,2);
34  
35      Parentheses missing around "local" list at -e line 1.
36        local $a, $b = (1,2);
37  
38      Bareword found in conditional at -e line 1.
39        use warnings 'bareword'; my $x = print(ABC || 1);
40  
41      Value of %s may be \"0\"; use \"defined\" 
42         $x = 1 if $x = <FH> ;
43         $x = 1 while $x = <FH> ;
44
45      Subroutine fred redefined at -e line 1.
46        sub fred{1;} sub fred{1;}
47  
48      Constant subroutine %s redefined 
49         sub fred() {1;} sub fred() {1;}
50  
51      Format FRED redefined at /tmp/x line 5.
52        format FRED =
53        .
54        format FRED =
55        .
56  
57      Array @%s missing the @ in argument %d of %s() 
58         push fred ;
59  
60      Hash %%%s missing the %% in argument %d of %s() 
61         keys joe ;
62  
63      Statement unlikely to be reached
64         (Maybe you meant system() when you said exec()?
65         exec "true" ; my $a
66
67      defined(@array) is deprecated
68         (Maybe you should just omit the defined()?)
69         my @a ; defined @a ;
70         defined (@a = (1,2,3)) ;
71
72      defined(%hash) is deprecated
73         (Maybe you should just omit the defined()?)
74         my %h ; defined %h ;
75
76      "my %s" used in sort comparison
77
78      $[ used in comparison (did you mean $] ?)
79
80      length() used on @array (did you mean "scalar(@array)"?)
81      length() used on %hash (did you mean "scalar(keys %hash)"?)
82
83      /---/ should probably be written as "---"
84         join(/---/, @foo);
85
86     %s() called too early to check prototype            [Perl_peep]
87         fred() ; sub fred ($$) {}
88
89
90     Package '%s' not found (did you use the incorrect case?)
91
92     Use of /g modifier is meaningless in split
93
94     Possible precedence problem on bitwise %c operator  [Perl_ck_bitop]
95
96     Mandatory Warnings 
97     ------------------
98     Prototype mismatch:         [cv_ckproto]
99         sub fred() ;
100         sub fred($) {}
101
102     oops: oopsAV                [oopsAV]        TODO
103     oops: oopsHV                [oopsHV]        TODO
104     
105 __END__
106 # op.c
107 use warnings 'syntax' ;
108 1 if $a = 1 ;
109 1 if $a
110   = 1 ;
111 no warnings 'syntax' ;
112 1 if $a = 1 ;
113 1 if $a
114   = 1 ;
115 EXPECT
116 Found = in conditional, should be == at - line 3.
117 Found = in conditional, should be == at - line 4.
118 ########
119 # op.c
120 use warnings 'syntax' ;
121 use constant foo => 1;
122 1 if $a = foo ;
123 no warnings 'syntax' ;
124 1 if $a = foo ;
125 EXPECT
126 ########
127 # op.c
128 my (@foo, %foo);
129 %main::foo->{"bar"};
130 %foo->{"bar"};
131 @main::foo->[23];
132 @foo->[23];
133 $main::foo = {}; %$main::foo->{"bar"};
134 $foo = {}; %$foo->{"bar"};
135 $main::foo = []; @$main::foo->[34];
136 $foo = []; @$foo->[34];
137 no warnings 'deprecated';
138 %main::foo->{"bar"};
139 %foo->{"bar"};
140 @main::foo->[23];
141 @foo->[23];
142 $main::foo = {}; %$main::foo->{"bar"};
143 $foo = {}; %$foo->{"bar"};
144 $main::foo = []; @$main::foo->[34];
145 $foo = []; @$foo->[34];
146 EXPECT
147 Using a hash as a reference is deprecated at - line 3.
148 Using a hash as a reference is deprecated at - line 4.
149 Using an array as a reference is deprecated at - line 5.
150 Using an array as a reference is deprecated at - line 6.
151 Using a hash as a reference is deprecated at - line 7.
152 Using a hash as a reference is deprecated at - line 8.
153 Using an array as a reference is deprecated at - line 9.
154 Using an array as a reference is deprecated at - line 10.
155 ########
156 # op.c
157 use warnings 'void' ; close STDIN ;
158 #line 2
159 1 x 3 ;                 # OP_REPEAT (folded)
160 (1) x 3 ;               # OP_REPEAT
161                         # OP_GVSV
162 wantarray ;             # OP_WANTARRAY
163                         # OP_GV
164                         # OP_PADSV
165                         # OP_PADAV
166                         # OP_PADHV
167                         # OP_PADANY
168                         # OP_AV2ARYLEN
169 ref ;                   # OP_REF
170 \@a ;                   # OP_REFGEN
171 \$a ;                   # OP_SREFGEN
172 defined $a ;            # OP_DEFINED
173 hex $a ;                # OP_HEX
174 oct $a ;                # OP_OCT
175 length $a ;             # OP_LENGTH
176 substr $a,1 ;           # OP_SUBSTR
177 vec $a,1,2 ;            # OP_VEC
178 index $a,1,2 ;          # OP_INDEX
179 rindex $a,1,2 ;         # OP_RINDEX
180 sprintf $a ;            # OP_SPRINTF
181 $a[0] ;                 # OP_AELEM
182                         # OP_AELEMFAST
183 @a[0] ;                 # OP_ASLICE
184 #values %a ;            # OP_VALUES
185 #keys %a ;              # OP_KEYS
186 $a{0} ;                 # OP_HELEM
187 @a{0} ;                 # OP_HSLICE
188 unpack "a", "a" ;       # OP_UNPACK
189 pack $a,"" ;            # OP_PACK
190 join "" ;               # OP_JOIN
191 (@a)[0,1] ;             # OP_LSLICE
192                         # OP_ANONLIST
193                         # OP_ANONHASH
194 sort(1,2) ;             # OP_SORT
195 reverse(1,2) ;          # OP_REVERSE
196                         # OP_RANGE
197                         # OP_FLIP
198 (1 ..2) ;               # OP_FLOP
199 caller ;                # OP_CALLER
200 fileno STDIN ;          # OP_FILENO
201 eof STDIN ;             # OP_EOF
202 tell STDIN ;            # OP_TELL
203 readlink 1;             # OP_READLINK
204 time ;                  # OP_TIME
205 localtime ;             # OP_LOCALTIME
206 gmtime ;                # OP_GMTIME
207 eval { getgrnam 1 };    # OP_GGRNAM
208 eval { getgrgid 1 };    # OP_GGRGID
209 eval { getpwnam 1 };    # OP_GPWNAM
210 eval { getpwuid 1 };    # OP_GPWUID
211 prototype "foo";        # OP_PROTOTYPE
212 $a ~~ $b;               # OP_SMARTMATCH
213 $a <=> $b;              # OP_NCMP
214 use 5.015;
215 __SUB__                 # OP_RUNCV
216 EXPECT
217 Useless use of a constant ("111") in void context at - line 2.
218 Useless use of repeat (x) in void context at - line 3.
219 Useless use of wantarray in void context at - line 5.
220 Useless use of reference-type operator in void context at - line 12.
221 Useless use of reference constructor in void context at - line 13.
222 Useless use of single ref constructor in void context at - line 14.
223 Useless use of defined operator in void context at - line 15.
224 Useless use of hex in void context at - line 16.
225 Useless use of oct in void context at - line 17.
226 Useless use of length in void context at - line 18.
227 Useless use of substr in void context at - line 19.
228 Useless use of vec in void context at - line 20.
229 Useless use of index in void context at - line 21.
230 Useless use of rindex in void context at - line 22.
231 Useless use of sprintf in void context at - line 23.
232 Useless use of array element in void context at - line 24.
233 Useless use of array slice in void context at - line 26.
234 Useless use of hash element in void context at - line 29.
235 Useless use of hash slice in void context at - line 30.
236 Useless use of unpack in void context at - line 31.
237 Useless use of pack in void context at - line 32.
238 Useless use of join or string in void context at - line 33.
239 Useless use of list slice in void context at - line 34.
240 Useless use of sort in void context at - line 37.
241 Useless use of reverse in void context at - line 38.
242 Useless use of range (or flop) in void context at - line 41.
243 Useless use of caller in void context at - line 42.
244 Useless use of fileno in void context at - line 43.
245 Useless use of eof in void context at - line 44.
246 Useless use of tell in void context at - line 45.
247 Useless use of readlink in void context at - line 46.
248 Useless use of time in void context at - line 47.
249 Useless use of localtime in void context at - line 48.
250 Useless use of gmtime in void context at - line 49.
251 Useless use of getgrnam in void context at - line 50.
252 Useless use of getgrgid in void context at - line 51.
253 Useless use of getpwnam in void context at - line 52.
254 Useless use of getpwuid in void context at - line 53.
255 Useless use of subroutine prototype in void context at - line 54.
256 Useless use of smart match in void context at - line 55.
257 Useless use of numeric comparison (<=>) in void context at - line 56.
258 Useless use of __SUB__ in void context at - line 58.
259 ########
260 # op.c
261 use warnings 'void' ; close STDIN ;
262 my $x = sort (2,1,3);
263 no warnings 'void' ;
264 $x = sort (2,1,3);
265 EXPECT
266 Useless use of sort in scalar context at - line 3.
267 ########
268 # op.c
269 no warnings 'void' ; close STDIN ;
270 1 x 3 ;                 # OP_REPEAT
271                         # OP_GVSV
272 wantarray ;             # OP_WANTARRAY
273                         # OP_GV
274                         # OP_PADSV
275                         # OP_PADAV
276                         # OP_PADHV
277                         # OP_PADANY
278                         # OP_AV2ARYLEN
279 ref ;                   # OP_REF
280 \@a ;                   # OP_REFGEN
281 \$a ;                   # OP_SREFGEN
282 defined $a ;            # OP_DEFINED
283 hex $a ;                # OP_HEX
284 oct $a ;                # OP_OCT
285 length $a ;             # OP_LENGTH
286 substr $a,1 ;           # OP_SUBSTR
287 vec $a,1,2 ;            # OP_VEC
288 index $a,1,2 ;          # OP_INDEX
289 rindex $a,1,2 ;         # OP_RINDEX
290 sprintf $a ;            # OP_SPRINTF
291 $a[0] ;                 # OP_AELEM
292                         # OP_AELEMFAST
293 @a[0] ;                 # OP_ASLICE
294 #values %a ;            # OP_VALUES
295 #keys %a ;              # OP_KEYS
296 $a{0} ;                 # OP_HELEM
297 @a{0} ;                 # OP_HSLICE
298 unpack "a", "a" ;       # OP_UNPACK
299 pack $a,"" ;            # OP_PACK
300 join "" ;               # OP_JOIN
301 (@a)[0,1] ;             # OP_LSLICE
302                         # OP_ANONLIST
303                         # OP_ANONHASH
304 sort(1,2) ;             # OP_SORT
305 reverse(1,2) ;          # OP_REVERSE
306                         # OP_RANGE
307                         # OP_FLIP
308 (1 ..2) ;               # OP_FLOP
309 caller ;                # OP_CALLER
310 fileno STDIN ;          # OP_FILENO
311 eof STDIN ;             # OP_EOF
312 tell STDIN ;            # OP_TELL
313 readlink 1;             # OP_READLINK
314 time ;                  # OP_TIME
315 localtime ;             # OP_LOCALTIME
316 gmtime ;                # OP_GMTIME
317 eval { getgrnam 1 };    # OP_GGRNAM
318 eval { getgrgid 1 };    # OP_GGRGID
319 eval { getpwnam 1 };    # OP_GPWNAM
320 eval { getpwuid 1 };    # OP_GPWUID
321 prototype "foo";        # OP_PROTOTYPE
322 EXPECT
323 ########
324 # op.c
325 use warnings 'void' ;
326 for (@{[0]}) { "$_" }           # check warning isn't duplicated
327 no warnings 'void' ;
328 for (@{[0]}) { "$_" }           # check warning isn't duplicated
329 EXPECT
330 Useless use of string in void context at - line 3.
331 ########
332 # op.c
333 use warnings 'void' ;
334 use Config ;
335 BEGIN {
336     if ( ! $Config{d_telldir}) {
337         print <<EOM ;
338 SKIPPED
339 # telldir not present
340 EOM
341         exit 
342     }
343 }
344 telldir 1 ;             # OP_TELLDIR
345 no warnings 'void' ;
346 telldir 1 ;             # OP_TELLDIR
347 EXPECT
348 Useless use of telldir in void context at - line 13.
349 ########
350 # op.c
351 use warnings 'void' ;
352 use Config ;
353 BEGIN {
354     if ( ! $Config{d_getppid}) {
355         print <<EOM ;
356 SKIPPED
357 # getppid not present
358 EOM
359         exit 
360     }
361 }
362 getppid ;               # OP_GETPPID
363 no warnings 'void' ;
364 getppid ;               # OP_GETPPID
365 EXPECT
366 Useless use of getppid in void context at - line 13.
367 ########
368 # op.c
369 use warnings 'void' ;
370 use Config ;
371 BEGIN {
372     if ( ! $Config{d_getpgrp}) {
373         print <<EOM ;
374 SKIPPED
375 # getpgrp not present
376 EOM
377         exit 
378     }
379 }
380 getpgrp ;               # OP_GETPGRP
381 no warnings 'void' ;
382 getpgrp ;               # OP_GETPGRP
383 EXPECT
384 Useless use of getpgrp in void context at - line 13.
385 ########
386 # op.c
387 use warnings 'void' ;
388 use Config ;
389 BEGIN {
390     if ( ! $Config{d_times}) {
391         print <<EOM ;
392 SKIPPED
393 # times not present
394 EOM
395         exit 
396     }
397 }
398 times ;                 # OP_TMS
399 no warnings 'void' ;
400 times ;                 # OP_TMS
401 EXPECT
402 Useless use of times in void context at - line 13.
403 ########
404 # op.c
405 use warnings 'void' ;
406 use Config ;
407 BEGIN {
408     if ( ! $Config{d_getprior} or $^O eq 'os2') { # Locks before fixpak22
409         print <<EOM ;
410 SKIPPED
411 # getpriority not present
412 EOM
413         exit 
414     }
415 }
416 getpriority 1,2;        # OP_GETPRIORITY
417 no warnings 'void' ;
418 getpriority 1,2;        # OP_GETPRIORITY
419 EXPECT
420 Useless use of getpriority in void context at - line 13.
421 ########
422 # op.c
423 use warnings 'void' ;
424 use Config ;
425 BEGIN {
426     if ( ! $Config{d_getlogin}) {
427         print <<EOM ;
428 SKIPPED
429 # getlogin not present
430 EOM
431         exit 
432     }
433 }
434 getlogin ;                      # OP_GETLOGIN
435 no warnings 'void' ;
436 getlogin ;                      # OP_GETLOGIN
437 EXPECT
438 Useless use of getlogin in void context at - line 13.
439 ########
440 # op.c
441 use warnings 'void' ;
442 use Config ; BEGIN {
443 if ( ! $Config{d_socket}) {
444     print <<EOM ;
445 SKIPPED
446 # getsockname not present
447 # getpeername not present
448 # gethostbyname not present
449 # gethostbyaddr not present
450 # gethostent not present
451 # getnetbyname not present
452 # getnetbyaddr not present
453 # getnetent not present
454 # getprotobyname not present
455 # getprotobynumber not present
456 # getprotoent not present
457 # getservbyname not present
458 # getservbyport not present
459 # getservent not present
460 EOM
461     exit 
462 } }
463 getsockname STDIN ;     # OP_GETSOCKNAME
464 getpeername STDIN ;     # OP_GETPEERNAME
465 gethostbyname 1 ;       # OP_GHBYNAME
466 gethostbyaddr 1,2;      # OP_GHBYADDR
467 gethostent ;            # OP_GHOSTENT
468 getnetbyname 1 ;        # OP_GNBYNAME
469 getnetbyaddr 1,2 ;      # OP_GNBYADDR
470 getnetent ;             # OP_GNETENT
471 getprotobyname 1;       # OP_GPBYNAME
472 getprotobynumber 1;     # OP_GPBYNUMBER
473 getprotoent ;           # OP_GPROTOENT
474 getservbyname 1,2;      # OP_GSBYNAME
475 getservbyport 1,2;      # OP_GSBYPORT
476 getservent ;            # OP_GSERVENT
477
478 no warnings 'void' ;
479 getsockname STDIN ;     # OP_GETSOCKNAME
480 getpeername STDIN ;     # OP_GETPEERNAME
481 gethostbyname 1 ;       # OP_GHBYNAME
482 gethostbyaddr 1,2;      # OP_GHBYADDR
483 gethostent ;            # OP_GHOSTENT
484 getnetbyname 1 ;        # OP_GNBYNAME
485 getnetbyaddr 1,2 ;      # OP_GNBYADDR
486 getnetent ;             # OP_GNETENT
487 getprotobyname 1;       # OP_GPBYNAME
488 getprotobynumber 1;     # OP_GPBYNUMBER
489 getprotoent ;           # OP_GPROTOENT
490 getservbyname 1,2;      # OP_GSBYNAME
491 getservbyport 1,2;      # OP_GSBYPORT
492 getservent ;            # OP_GSERVENT
493 INIT {
494    # some functions may not be there, so we exit without running
495    exit;
496 }
497 EXPECT
498 Useless use of getsockname in void context at - line 24.
499 Useless use of getpeername in void context at - line 25.
500 Useless use of gethostbyname in void context at - line 26.
501 Useless use of gethostbyaddr in void context at - line 27.
502 Useless use of gethostent in void context at - line 28.
503 Useless use of getnetbyname in void context at - line 29.
504 Useless use of getnetbyaddr in void context at - line 30.
505 Useless use of getnetent in void context at - line 31.
506 Useless use of getprotobyname in void context at - line 32.
507 Useless use of getprotobynumber in void context at - line 33.
508 Useless use of getprotoent in void context at - line 34.
509 Useless use of getservbyname in void context at - line 35.
510 Useless use of getservbyport in void context at - line 36.
511 Useless use of getservent in void context at - line 37.
512 ########
513 # op.c
514 use warnings 'void' ;
515 *a ; # OP_RV2GV
516 $a ; # OP_RV2SV
517 @a ; # OP_RV2AV
518 %a ; # OP_RV2HV
519 no warnings 'void' ;
520 *a ; # OP_RV2GV
521 $a ; # OP_RV2SV
522 @a ; # OP_RV2AV
523 %a ; # OP_RV2HV
524 EXPECT
525 Useless use of a variable in void context at - line 3.
526 Useless use of a variable in void context at - line 4.
527 Useless use of a variable in void context at - line 5.
528 Useless use of a variable in void context at - line 6.
529 ########
530 # op.c
531 use warnings 'void' ;
532 "abc"; # OP_CONST
533 7 ; # OP_CONST
534 "x" . "y"; # optimized to OP_CONST
535 2 + 2; # optimized to OP_CONST
536 use constant U => undef;
537 U;
538 qq/"    \n/;
539 5 || print "bad\n";     # test OPpCONST_SHORTCIRCUIT
540 print "boo\n" if U;     # test OPpCONST_SHORTCIRCUIT
541 no warnings 'void' ;
542 "abc"; # OP_CONST
543 7 ; # OP_CONST
544 "x" . "y"; # optimized to OP_CONST
545 2 + 2; # optimized to OP_CONST
546 EXPECT
547 Useless use of a constant ("abc") in void context at - line 3.
548 Useless use of a constant (7) in void context at - line 4.
549 Useless use of a constant ("xy") in void context at - line 5.
550 Useless use of a constant (4) in void context at - line 6.
551 Useless use of a constant (undef) in void context at - line 8.
552 Useless use of a constant ("\"\t\n") in void context at - line 9.
553 ########
554 # op.c
555 use utf8;
556 use open qw( :utf8 :std );
557 use warnings 'void' ;
558 "àḆc"; # OP_CONST
559 "Ẋ" . "ƴ"; # optimized to OP_CONST
560 FOO;     # Bareword optimized to OP_CONST
561 use constant ů => undef;
562 ů;
563 5 || print "bad\n";     # test OPpCONST_SHORTCIRCUIT
564 print "boo\n" if ů;    # test OPpCONST_SHORTCIRCUIT
565 no warnings 'void' ;
566 "àḆc"; # OP_CONST
567 "Ẋ" . "ƴ"; # optimized to OP_CONST
568 EXPECT
569 Useless use of a constant ("\340\x{1e06}c") in void context at - line 5.
570 Useless use of a constant ("\x{1e8a}\x{1b4}") in void context at - line 6.
571 Useless use of a constant ("\x{ff26}\x{ff2f}\x{ff2f}") in void context at - line 7.
572 Useless use of a constant (undef) in void context at - line 9.
573 ########
574 # op.c
575 #
576 use warnings 'misc' ;
577 my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;my $d = 'test';
578 @a =~ /abc/ ;
579 @a2 =~ s/a/b/ ;
580 @a3 =~ tr/a/b/ ;
581 @$b =~ /abc/ ;
582 @$b =~ s/a/b/ ;
583 @$b =~ tr/a/b/ ;
584 %a =~ /abc/ ;
585 %a2 =~ s/a/b/ ;
586 %a3 =~ tr/a/b/ ;
587 %$c =~ /abc/ ;
588 %$c =~ s/a/b/ ;
589 %$c =~ tr/a/b/ ;
590 $d =~ tr/a/b/d ;
591 $d2 =~ tr/a/bc/;
592 {
593 no warnings 'misc' ;
594 my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; my $d = 'test';
595 @a =~ /abc/ ;
596 @a =~ s/a/b/ ;
597 @a =~ tr/a/b/ ;
598 @$b =~ /abc/ ;
599 @$b =~ s/a/b/ ;
600 @$b =~ tr/a/b/ ;
601 %a =~ /abc/ ;
602 %a =~ s/a/b/ ;
603 %a =~ tr/a/b/ ;
604 %$c =~ /abc/ ;
605 %$c =~ s/a/b/ ;
606 %$c =~ tr/a/b/ ;
607 $d =~ tr/a/b/d ;
608 $d =~ tr/a/bc/ ;
609 }
610 EXPECT
611 Applying pattern match (m//) to @a will act on scalar(@a) at - line 5.
612 Applying substitution (s///) to @a2 will act on scalar(@a2) at - line 6.
613 Applying transliteration (tr///) to @a3 will act on scalar(@a3) at - line 7.
614 Applying pattern match (m//) to @array will act on scalar(@array) at - line 8.
615 Applying substitution (s///) to @array will act on scalar(@array) at - line 9.
616 Applying transliteration (tr///) to @array will act on scalar(@array) at - line 10.
617 Applying pattern match (m//) to %a will act on scalar(%a) at - line 11.
618 Applying substitution (s///) to %a2 will act on scalar(%a2) at - line 12.
619 Applying transliteration (tr///) to %a3 will act on scalar(%a3) at - line 13.
620 Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 14.
621 Applying substitution (s///) to %hash will act on scalar(%hash) at - line 15.
622 Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 16.
623 Useless use of /d modifier in transliteration operator at - line 17.
624 Replacement list is longer than search list at - line 18.
625 Can't modify array dereference in substitution (s///) at - line 6, near "s/a/b/ ;"
626 BEGIN not safe after errors--compilation aborted at - line 20.
627 ########
628 # op.c
629 use warnings 'parenthesis' ;
630 my $a, $b = (1,2);
631 my @foo,%bar,   $quux; # there's a TAB here
632 my $x, $y or print;
633 no warnings 'parenthesis' ;
634 my $c, $d = (1,2);
635 EXPECT
636 Parentheses missing around "my" list at - line 3.
637 Parentheses missing around "my" list at - line 4.
638 ########
639 # op.c
640 use warnings 'parenthesis' ;
641 our $a, $b = (1,2);
642 no warnings 'parenthesis' ;
643 our $c, $d = (1,2);
644 EXPECT
645 Parentheses missing around "our" list at - line 3.
646 ########
647 # op.c
648 use warnings 'parenthesis' ;
649 local $a, $b = (1,2);
650 local *f, *g;
651 no warnings 'parenthesis' ;
652 local $c, $d = (1,2);
653 EXPECT
654 Parentheses missing around "local" list at - line 3.
655 Parentheses missing around "local" list at - line 4.
656 ########
657 # op.c
658 use warnings 'bareword' ;
659 print (ABC || 1) ;
660 no warnings 'bareword' ;
661 print (ABC || 1) ;
662 EXPECT
663 Bareword found in conditional at - line 3.
664 ########
665 --FILE-- abc
666
667 --FILE--
668 # op.c
669 use warnings 'misc' ;
670 open FH, "<abc" ;
671 $x = 1 if $x = <FH> ;
672 $x = 1 if $x
673      = <FH> ;
674 no warnings 'misc' ;
675 $x = 1 if $x = <FH> ;
676 $x = 1 if $x
677      = <FH> ;
678 EXPECT
679 Value of <HANDLE> construct can be "0"; test with defined() at - line 4.
680 Value of <HANDLE> construct can be "0"; test with defined() at - line 5.
681 ########
682 # op.c
683 use warnings 'misc' ;
684 opendir FH, "." ;
685 $x = 1 if $x = readdir FH ;
686 $x = 1 if $x
687     = readdir FH ;
688 no warnings 'misc' ;
689 $x = 1 if $x = readdir FH ;
690 $x = 1 if $x
691     = readdir FH ;
692 closedir FH ;
693 EXPECT
694 Value of readdir() operator can be "0"; test with defined() at - line 4.
695 Value of readdir() operator can be "0"; test with defined() at - line 5.
696 ########
697 # op.c
698 use warnings 'misc' ;
699 $x = 1 if $x = <*> ;
700 $x = 1 if $x
701     = <*> ;
702 no warnings 'misc' ;
703 $x = 1 if $x = <*> ;
704 $x = 1 if $x
705     = <*> ;
706 EXPECT
707 Value of glob construct can be "0"; test with defined() at - line 3.
708 Value of glob construct can be "0"; test with defined() at - line 4.
709 ########
710 # op.c
711 use warnings 'misc' ;
712 %a = (1,2,3,4) ;
713 $x = 1 if $x = each %a ;
714 no warnings 'misc' ;
715 $x = 1 if $x = each %a ;
716 EXPECT
717 Value of each() operator can be "0"; test with defined() at - line 4.
718 ########
719 # op.c
720 use warnings 'misc' ;
721 $x = 1 while $x = <*> and 0 ;
722 no warnings 'misc' ;
723 $x = 1 while $x = <*> and 0 ;
724 EXPECT
725 Value of glob construct can be "0"; test with defined() at - line 3.
726 ########
727 # op.c
728 use warnings 'misc' ;
729 opendir FH, "." ;
730 $x = 1 while $x = readdir FH and 0 ;
731 no warnings 'misc' ;
732 $x = 1 while $x = readdir FH and 0 ;
733 closedir FH ;
734 EXPECT
735 Value of readdir() operator can be "0"; test with defined() at - line 4.
736 ########
737 # op.c
738 use warnings 'misc';
739 open FH, "<abc";
740 ($_ = <FH>) // ($_ = 1);
741 opendir DH, ".";
742 %a = (1,2,3,4) ;
743 EXPECT
744 ########
745 # op.c
746 use warnings 'redefine' ;
747 sub fred {}
748 sub fred {}
749 sub fred { # warning should be for this line
750 }
751 no warnings 'redefine' ;
752 sub fred {}
753 sub fred {
754 }
755 EXPECT
756 Subroutine fred redefined at - line 4.
757 Subroutine fred redefined at - line 5.
758 ########
759 # op.c
760 use warnings 'redefine' ;
761 sub fred () { 1 }
762 sub fred () { 1 }
763 no warnings 'redefine' ;
764 sub fred () { 1 }
765 EXPECT
766 Constant subroutine fred redefined at - line 4.
767 ########
768 # op.c
769 sub fred () { 1 }
770 sub fred () { 2 }
771 EXPECT
772 Constant subroutine fred redefined at - line 3.
773 ########
774 # op.c
775 sub fred () { 1 }
776 *fred = sub () { 2 };
777 EXPECT
778 Constant subroutine main::fred redefined at - line 3.
779 ########
780 # op.c
781 use feature "lexical_subs", "state";
782 my sub fred () { 1 }
783 sub fred { 2 };
784 my sub george { 1 }
785 sub george () { 2 } # should *not* produce redef warnings by default
786 state sub phred () { 1 }
787 sub phred { 2 };
788 state sub jorge { 1 }
789 sub jorge () { 2 } # should *not* produce redef warnings by default
790 EXPECT
791 The lexical_subs feature is experimental at - line 2.
792 Prototype mismatch: sub fred () vs none at - line 4.
793 Constant subroutine fred redefined at - line 4.
794 Prototype mismatch: sub george: none vs () at - line 6.
795 Prototype mismatch: sub phred () vs none at - line 8.
796 Constant subroutine phred redefined at - line 8.
797 Prototype mismatch: sub jorge: none vs () at - line 10.
798 ########
799 # op.c
800 no warnings 'redefine' ;
801 sub fred () { 1 }
802 sub fred () { 2 }
803 EXPECT
804 ########
805 # op.c
806 no warnings 'redefine' ;
807 sub fred () { 1 }
808 *fred = sub () { 2 };
809 EXPECT
810 ########
811 # op.c
812 use warnings 'redefine' ;
813 format FRED =
814 .
815 format FRED =
816 .
817 no warnings 'redefine' ;
818 format FRED =
819 .
820 EXPECT
821 Format FRED redefined at - line 5.
822 ########
823 # op.c
824 push FRED;
825 no warnings 'deprecated' ;
826 push FRED;
827 EXPECT
828 Array @FRED missing the @ in argument 1 of push() at - line 2.
829 ########
830 # op.c
831 @a = keys FRED ;
832 no warnings 'deprecated' ;
833 @a = keys FRED ;
834 EXPECT
835 Hash %FRED missing the % in argument 1 of keys() at - line 2.
836 ########
837 # op.c
838 use warnings 'syntax' ;
839 exec "$^X -e 1" ; 
840 my $a
841 EXPECT
842 Statement unlikely to be reached at - line 4.
843         (Maybe you meant system() when you said exec()?)
844 ########
845 # op.c, no warning if exec isn't a statement.
846 use warnings 'syntax' ;
847 $a || exec "$^X -e 1" ;
848 my $a
849 EXPECT
850 ########
851 # op.c
852 defined(@a);
853 EXPECT
854 defined(@array) is deprecated at - line 2.
855         (Maybe you should just omit the defined()?)
856 ########
857 # op.c
858 my @a; defined(@a);
859 EXPECT
860 defined(@array) is deprecated at - line 2.
861         (Maybe you should just omit the defined()?)
862 ########
863 # op.c
864 defined(@a = (1,2,3));
865 EXPECT
866 defined(@array) is deprecated at - line 2.
867         (Maybe you should just omit the defined()?)
868 ########
869 # op.c
870 defined(%h);
871 EXPECT
872 defined(%hash) is deprecated at - line 2.
873         (Maybe you should just omit the defined()?)
874 ########
875 # op.c
876 my %h; defined(%h);
877 EXPECT
878 defined(%hash) is deprecated at - line 2.
879         (Maybe you should just omit the defined()?)
880 ########
881 # op.c
882 no warnings 'syntax' ;
883 exec "$^X -e 1" ; 
884 my $a
885 EXPECT
886
887 ########
888 # op.c
889 sub fred();
890 sub fred($) {}
891 use constant foo=>bar; sub foo(@);
892 use constant bav=>bar; sub bav(); # no warning
893 sub btu; sub btu();
894 EXPECT
895 Prototype mismatch: sub main::fred () vs ($) at - line 3.
896 Prototype mismatch: sub foo () vs (@) at - line 4.
897 Prototype mismatch: sub btu: none vs () at - line 6.
898 ########
899 # op.c
900 use utf8;
901 use open qw( :utf8 :std );
902 sub frèd();
903 sub frèd($) {}
904 EXPECT
905 Prototype mismatch: sub main::frèd () vs ($) at - line 5.
906 ########
907 # op.c
908 use utf8;
909 use open qw( :utf8 :std );
910 use warnings;
911 eval "sub fòò (\$\0) {}";
912 EXPECT
913 Illegal character in prototype for main::fòò : $\0 at (eval 1) line 1.
914 ########
915 # op.c
916 use utf8;
917 use open qw( :utf8 :std );
918 use warnings;
919 eval "sub foo (\0) {}";
920 EXPECT
921 Illegal character in prototype for main::foo : \0 at (eval 1) line 1.
922 ########
923 # op.c
924 use utf8;
925 use open qw( :utf8 :std );
926 use warnings;
927 BEGIN { $::{"foo"} = "\$\0L\351on" }
928 BEGIN { eval "sub foo (\$\0L\x{c3}\x{a9}on) {}"; }
929 EXPECT
930 Illegal character in prototype for main::foo : $\x{0}L... at (eval 1) line 1.
931 ########
932 # op.c
933 use utf8;
934 use open qw( :utf8 :std );
935 use warnings;
936 BEGIN { eval "sub foo (\0) {}"; }
937 EXPECT
938 Illegal character in prototype for main::foo : \0 at (eval 1) line 1.
939 ########
940 # op.c
941 use warnings;
942 eval "sub foo (\xAB) {}";
943 EXPECT
944 Illegal character in prototype for main::foo : \x{ab} at (eval 1) line 1.
945 ########
946 # op.c
947 use utf8;
948 use open qw( :utf8 :std );
949 use warnings;
950 BEGIN { eval "sub foo (\x{30cb}) {}"; }
951 EXPECT
952 Illegal character in prototype for main::foo : \x{30cb} at (eval 1) line 1.
953 ########
954 # op.c
955 use utf8;
956 use open qw( :utf8 :std );
957 use warnings;
958 BEGIN { $::{"foo"} = "\x{30cb}" }
959 BEGIN { eval "sub foo {}"; }
960 EXPECT
961 Prototype mismatch: sub main::foo (ニ) vs none at (eval 1) line 1.
962 ########
963 # op.c
964 $^W = 0 ;
965 sub fred() ;
966 sub fred($) {}
967 {
968     no warnings 'prototype' ;
969     sub Fred() ;
970     sub Fred($) {}
971     use warnings 'prototype' ;
972     sub freD() ;
973     sub freD($) {}
974 }
975 sub FRED() ;
976 sub FRED($) {}
977 EXPECT
978 Prototype mismatch: sub main::fred () vs ($) at - line 4.
979 Prototype mismatch: sub main::freD () vs ($) at - line 11.
980 Prototype mismatch: sub main::FRED () vs ($) at - line 14.
981 ########
982 # op.c [S_simplify_sort]
983 # [perl #86136]
984 my @tests = split /^/, '
985   sort {$a <=> $b} @a;
986   sort {$a cmp $b} @a;
987   { use integer; sort {$a <=> $b} @a}
988   sort {$b <=> $a} @a;
989   sort {$b cmp $a} @a;
990   { use integer; sort {$b <=> $a} @a}
991 ';
992 for my $pragma ('use warnings "syntax";', '') {
993   for my $vars ('', 'my $a;', 'my $b;', 'my ($a,$b);') {
994     for my $inner_stmt ('', 'print;', 'func();') {
995       eval "#line " . ++$line . "01 -\n$pragma\n$vars"
996           . join "", map s/sort \{\K/$inner_stmt/r, @tests;
997       $@ and die;
998     }
999   }
1000 }
1001 sub func{}
1002 use warnings 'syntax';
1003 my $a;
1004 # These used to be errors!
1005 sort { ; } $a <=> $b;
1006 sort { ; } $a, "<=>";
1007 sort { ; } $a, $cmp;
1008 sort $a, $b if $cmpany_name;
1009 sort if $a + $cmp;
1010 sort @t; $a + $cmp;
1011 EXPECT
1012 "my $a" used in sort comparison at - line 403.
1013 "my $a" used in sort comparison at - line 404.
1014 "my $a" used in sort comparison at - line 405.
1015 "my $a" used in sort comparison at - line 406.
1016 "my $a" used in sort comparison at - line 407.
1017 "my $a" used in sort comparison at - line 408.
1018 "my $a" used in sort comparison at - line 503.
1019 "my $a" used in sort comparison at - line 504.
1020 "my $a" used in sort comparison at - line 505.
1021 "my $a" used in sort comparison at - line 506.
1022 "my $a" used in sort comparison at - line 507.
1023 "my $a" used in sort comparison at - line 508.
1024 "my $a" used in sort comparison at - line 603.
1025 "my $a" used in sort comparison at - line 604.
1026 "my $a" used in sort comparison at - line 605.
1027 "my $a" used in sort comparison at - line 606.
1028 "my $a" used in sort comparison at - line 607.
1029 "my $a" used in sort comparison at - line 608.
1030 "my $b" used in sort comparison at - line 703.
1031 "my $b" used in sort comparison at - line 704.
1032 "my $b" used in sort comparison at - line 705.
1033 "my $b" used in sort comparison at - line 706.
1034 "my $b" used in sort comparison at - line 707.
1035 "my $b" used in sort comparison at - line 708.
1036 "my $b" used in sort comparison at - line 803.
1037 "my $b" used in sort comparison at - line 804.
1038 "my $b" used in sort comparison at - line 805.
1039 "my $b" used in sort comparison at - line 806.
1040 "my $b" used in sort comparison at - line 807.
1041 "my $b" used in sort comparison at - line 808.
1042 "my $b" used in sort comparison at - line 903.
1043 "my $b" used in sort comparison at - line 904.
1044 "my $b" used in sort comparison at - line 905.
1045 "my $b" used in sort comparison at - line 906.
1046 "my $b" used in sort comparison at - line 907.
1047 "my $b" used in sort comparison at - line 908.
1048 "my $a" used in sort comparison at - line 1003.
1049 "my $b" used in sort comparison at - line 1003.
1050 "my $a" used in sort comparison at - line 1004.
1051 "my $b" used in sort comparison at - line 1004.
1052 "my $a" used in sort comparison at - line 1005.
1053 "my $b" used in sort comparison at - line 1005.
1054 "my $b" used in sort comparison at - line 1006.
1055 "my $a" used in sort comparison at - line 1006.
1056 "my $b" used in sort comparison at - line 1007.
1057 "my $a" used in sort comparison at - line 1007.
1058 "my $b" used in sort comparison at - line 1008.
1059 "my $a" used in sort comparison at - line 1008.
1060 "my $a" used in sort comparison at - line 1103.
1061 "my $b" used in sort comparison at - line 1103.
1062 "my $a" used in sort comparison at - line 1104.
1063 "my $b" used in sort comparison at - line 1104.
1064 "my $a" used in sort comparison at - line 1105.
1065 "my $b" used in sort comparison at - line 1105.
1066 "my $b" used in sort comparison at - line 1106.
1067 "my $a" used in sort comparison at - line 1106.
1068 "my $b" used in sort comparison at - line 1107.
1069 "my $a" used in sort comparison at - line 1107.
1070 "my $b" used in sort comparison at - line 1108.
1071 "my $a" used in sort comparison at - line 1108.
1072 "my $a" used in sort comparison at - line 1203.
1073 "my $b" used in sort comparison at - line 1203.
1074 "my $a" used in sort comparison at - line 1204.
1075 "my $b" used in sort comparison at - line 1204.
1076 "my $a" used in sort comparison at - line 1205.
1077 "my $b" used in sort comparison at - line 1205.
1078 "my $b" used in sort comparison at - line 1206.
1079 "my $a" used in sort comparison at - line 1206.
1080 "my $b" used in sort comparison at - line 1207.
1081 "my $a" used in sort comparison at - line 1207.
1082 "my $b" used in sort comparison at - line 1208.
1083 "my $a" used in sort comparison at - line 1208.
1084 ########
1085 # op.c [S_simplify_sort]
1086 use warnings 'syntax'; use 5.01;
1087 state $a;
1088 sort { $a <=> $b } ();
1089 EXPECT
1090 "state $a" used in sort comparison at - line 4.
1091 ########
1092 # op.c [Perl_ck_cmp]
1093 use warnings 'syntax' ;
1094 no warnings 'deprecated';
1095 @a = $[ < 5;
1096 @a = $[ > 5;
1097 @a = $[ <= 5;
1098 @a = $[ >= 5;
1099 @a = 42 < $[;
1100 @a = 42 > $[;
1101 @a = 42 <= $[;
1102 @a = 42 >= $[;
1103 use integer;
1104 @a = $[ < 5;
1105 @a = $[ > 5;
1106 @a = $[ <= 5;
1107 @a = $[ >= 5;
1108 @a = 42 < $[;
1109 @a = 42 > $[;
1110 @a = 42 <= $[;
1111 @a = 42 >= $[;
1112 no integer;
1113 @a = $[ < $5;
1114 @a = $[ > $5;
1115 @a = $[ <= $5;
1116 @a = $[ >= $5;
1117 @a = $42 < $[;
1118 @a = $42 > $[;
1119 @a = $42 <= $[;
1120 @a = $42 >= $[;
1121 use integer;
1122 @a = $[ < $5;
1123 @a = $[ > $5;
1124 @a = $[ <= $5;
1125 @a = $[ >= $5;
1126 @a = $42 < $[;
1127 @a = $42 > $[;
1128 @a = $42 <= $[;
1129 @a = $42 >= $[;
1130 EXPECT
1131 $[ used in numeric lt (<) (did you mean $] ?) at - line 4.
1132 $[ used in numeric gt (>) (did you mean $] ?) at - line 5.
1133 $[ used in numeric le (<=) (did you mean $] ?) at - line 6.
1134 $[ used in numeric ge (>=) (did you mean $] ?) at - line 7.
1135 $[ used in numeric lt (<) (did you mean $] ?) at - line 8.
1136 $[ used in numeric gt (>) (did you mean $] ?) at - line 9.
1137 $[ used in numeric le (<=) (did you mean $] ?) at - line 10.
1138 $[ used in numeric ge (>=) (did you mean $] ?) at - line 11.
1139 $[ used in numeric lt (<) (did you mean $] ?) at - line 13.
1140 $[ used in numeric gt (>) (did you mean $] ?) at - line 14.
1141 $[ used in numeric le (<=) (did you mean $] ?) at - line 15.
1142 $[ used in numeric ge (>=) (did you mean $] ?) at - line 16.
1143 $[ used in numeric lt (<) (did you mean $] ?) at - line 17.
1144 $[ used in numeric gt (>) (did you mean $] ?) at - line 18.
1145 $[ used in numeric le (<=) (did you mean $] ?) at - line 19.
1146 $[ used in numeric ge (>=) (did you mean $] ?) at - line 20.
1147 ########
1148 # op.c [Perl_ck_length]
1149 use warnings 'syntax' ;
1150 length(@a);
1151 length(%b);
1152 length(@$c);
1153 length(%$d);
1154 length($a);
1155 length(my %h);
1156 length(my @g);
1157 EXPECT
1158 length() used on @a (did you mean "scalar(@a)"?) at - line 3.
1159 length() used on %b (did you mean "scalar(keys %b)"?) at - line 4.
1160 length() used on @array (did you mean "scalar(@array)"?) at - line 5.
1161 length() used on %hash (did you mean "scalar(keys %hash)"?) at - line 6.
1162 length() used on %h (did you mean "scalar(keys %h)"?) at - line 8.
1163 length() used on @g (did you mean "scalar(@g)"?) at - line 9.
1164 ########
1165 # op.c
1166 use warnings 'syntax' ;
1167 join /---/, 'x', 'y', 'z';
1168 EXPECT
1169 /---/ should probably be written as "---" at - line 3.
1170 ########
1171 # op.c
1172 use utf8;
1173 use open qw( :utf8 :std );
1174 use warnings 'syntax' ;
1175 join /~~~/, 'x', 'y', 'z';
1176 EXPECT
1177 /~~~/ should probably be written as "~~~" at - line 5.
1178 ########
1179 # op.c [Perl_peep]
1180 use warnings 'prototype' ;
1181 fred() ; 
1182 sub fred ($$) {}
1183 no warnings 'prototype' ;
1184 joe() ; 
1185 sub joe ($$) {}
1186 EXPECT
1187 main::fred() called too early to check prototype at - line 3.
1188 ########
1189 # op.c [Perl_newATTRSUB]
1190 --FILE-- abc.pm
1191 use warnings 'void' ;
1192 BEGIN { $| = 1; print "in begin\n"; }
1193 CHECK { print "in check\n"; }
1194 INIT { print "in init\n"; }
1195 END { print "in end\n"; }
1196 print "in mainline\n";
1197 1;
1198 --FILE--
1199 use abc;
1200 delete $INC{"abc.pm"};
1201 require abc;
1202 do "abc.pm";
1203 EXPECT
1204 in begin
1205 in mainline
1206 in check
1207 in init
1208 in begin
1209 Too late to run CHECK block at abc.pm line 3.
1210 Too late to run INIT block at abc.pm line 4.
1211 in mainline
1212 in begin
1213 Too late to run CHECK block at abc.pm line 3.
1214 Too late to run INIT block at abc.pm line 4.
1215 in mainline
1216 in end
1217 in end
1218 in end
1219 ########
1220 # op.c [Perl_newATTRSUB]
1221 --FILE-- abc.pm
1222 no warnings 'void' ;
1223 BEGIN { $| = 1; print "in begin\n"; }
1224 CHECK { print "in check\n"; }
1225 INIT { print "in init\n"; }
1226 END { print "in end\n"; }
1227 print "in mainline\n";
1228 1;
1229 --FILE--
1230 require abc;
1231 do "abc.pm";
1232 EXPECT
1233 in begin
1234 in mainline
1235 in begin
1236 in mainline
1237 in end
1238 in end
1239 ########
1240 # op.c
1241 my @x;
1242 use warnings 'syntax' ;
1243 push(@x);
1244 unshift(@x);
1245 no warnings 'syntax' ;
1246 push(@x);
1247 unshift(@x);
1248 EXPECT
1249 Useless use of push with no values at - line 4.
1250 Useless use of unshift with no values at - line 5.
1251 ########
1252 # op.c
1253 # 20020401 mjd@plover.com at suggestion of jfriedl@yahoo.com
1254 use warnings 'regexp';
1255 split /blah/g, "blah";
1256 no warnings 'regexp';
1257 split /blah/g, "blah";
1258 EXPECT
1259 Use of /g modifier is meaningless in split at - line 4.
1260 ########
1261 # op.c
1262 use warnings 'precedence';
1263 $a = $b & $c == $d;
1264 $a = $b ^ $c != $d;
1265 $a = $b | $c > $d;
1266 $a = $b < $c & $d;
1267 $a = $b >= $c ^ $d;
1268 $a = $b <= $c | $d;
1269 $a = $b <=> $c & $d;
1270 $a &= $b == $c; $a |= $b == $c; $a ^= $b == $c; # shouldn't warn
1271 no warnings 'precedence';
1272 $a = $b & $c == $d;
1273 $a = $b ^ $c != $d;
1274 $a = $b | $c > $d;
1275 $a = $b < $c & $d;
1276 $a = $b >= $c ^ $d;
1277 $a = $b <= $c | $d;
1278 $a = $b <=> $c & $d;
1279 EXPECT
1280 Possible precedence problem on bitwise & operator at - line 3.
1281 Possible precedence problem on bitwise ^ operator at - line 4.
1282 Possible precedence problem on bitwise | operator at - line 5.
1283 Possible precedence problem on bitwise & operator at - line 6.
1284 Possible precedence problem on bitwise ^ operator at - line 7.
1285 Possible precedence problem on bitwise | operator at - line 8.
1286 Possible precedence problem on bitwise & operator at - line 9.
1287 ########
1288 # op.c
1289 use integer;
1290 use warnings 'precedence';
1291 $a = $b & $c == $d;
1292 $a = $b ^ $c != $d;
1293 $a = $b | $c > $d;
1294 $a = $b < $c & $d;
1295 $a = $b >= $c ^ $d;
1296 $a = $b <= $c | $d;
1297 $a = $b <=> $c & $d;
1298 no warnings 'precedence';
1299 $a = $b & $c == $d;
1300 $a = $b ^ $c != $d;
1301 $a = $b | $c > $d;
1302 $a = $b < $c & $d;
1303 $a = $b >= $c ^ $d;
1304 $a = $b <= $c | $d;
1305 $a = $b <=> $c & $d;
1306 EXPECT
1307 Possible precedence problem on bitwise & operator at - line 4.
1308 Possible precedence problem on bitwise ^ operator at - line 5.
1309 Possible precedence problem on bitwise | operator at - line 6.
1310 Possible precedence problem on bitwise & operator at - line 7.
1311 Possible precedence problem on bitwise ^ operator at - line 8.
1312 Possible precedence problem on bitwise | operator at - line 9.
1313 Possible precedence problem on bitwise & operator at - line 10.
1314 ########
1315 # op.c
1316
1317 # ok    => local() has desired effect;
1318 # ignore=> local() silently ignored
1319
1320 use warnings 'syntax';
1321
1322 local(undef);           # OP_UNDEF              ignore
1323 sub lval : lvalue {};
1324 local(lval());          # OP_ENTERSUB
1325 local($x **= 1);        # OP_POW
1326 local($x *=  1);        # OP_MULTIPLY
1327 local($x /=  1);        # OP_DIVIDE
1328 local($x %=  1);        # OP_MODULO
1329 local($x x=  1);        # OP_REPEAT
1330 local($x +=  1);        # OP_ADD
1331 local($x -=  1);        # OP_SUBTRACT
1332 local($x .=  1);        # OP_CONCAT
1333 local($x <<= 1);        # OP_LEFT_SHIFT
1334 local($x >>= 1);        # OP_RIGHT_SHIFT
1335 local($x &=  1);        # OP_BIT_AND
1336 local($x ^=  1);        # OP_BIT_XOR
1337 local($x |=  1);        # OP_BIT_OR
1338 {
1339     use integer;
1340     local($x *= 1);     # OP_I_MULTIPLY
1341     local($x /= 1);     # OP_I_DIVIDE
1342     local($x %= 1);     # OP_I_MODULO
1343     local($x += 1);     # OP_I_ADD
1344     local($x -= 1);     # OP_I_SUBTRACT
1345 }
1346 local($x?$y:$z) = 1;    # OP_COND_EXPR          ok
1347 # these two are fatal run-time errors instead
1348 #local(@$a);            # OP_RV2AV              ok
1349 #local(%$a);            # OP_RV2HV              ok
1350 local(*a);              # OP_RV2GV              ok
1351 local(@a[1,2]);         # OP_ASLICE             ok
1352 local(@a{1,2});         # OP_HSLICE             ok
1353 local(@a = (1,2));      # OP_AASSIGN
1354 local($$x);             # OP_RV2SV              ok
1355 local($#a);             # OP_AV2ARYLEN
1356 local($x =   1);        # OP_SASSIGN
1357 local($x &&= 1);        # OP_ANDASSIGN
1358 local($x ||= 1);        # OP_ORASSIGN
1359 local($x //= 1);        # OP_DORASSIGN
1360 local($a[0]);           # OP_AELEMFAST          ok
1361
1362 local(substr($x,0,1));  # OP_SUBSTR
1363 local(pos($x));         # OP_POS
1364 local(vec($x,0,1));     # OP_VEC
1365 local($a[$b]);          # OP_AELEM              ok
1366 local($a{$b});          # OP_HELEM              ok
1367
1368 no warnings 'syntax';
1369 EXPECT
1370 Useless localization of subroutine entry at - line 10.
1371 Useless localization of exponentiation (**) at - line 11.
1372 Useless localization of multiplication (*) at - line 12.
1373 Useless localization of division (/) at - line 13.
1374 Useless localization of modulus (%) at - line 14.
1375 Useless localization of repeat (x) at - line 15.
1376 Useless localization of addition (+) at - line 16.
1377 Useless localization of subtraction (-) at - line 17.
1378 Useless localization of concatenation (.) or string at - line 18.
1379 Useless localization of left bitshift (<<) at - line 19.
1380 Useless localization of right bitshift (>>) at - line 20.
1381 Useless localization of bitwise and (&) at - line 21.
1382 Useless localization of bitwise xor (^) at - line 22.
1383 Useless localization of bitwise or (|) at - line 23.
1384 Useless localization of integer multiplication (*) at - line 26.
1385 Useless localization of integer division (/) at - line 27.
1386 Useless localization of integer modulus (%) at - line 28.
1387 Useless localization of integer addition (+) at - line 29.
1388 Useless localization of integer subtraction (-) at - line 30.
1389 Useless localization of list assignment at - line 39.
1390 Useless localization of array length at - line 41.
1391 Useless localization of scalar assignment at - line 42.
1392 Useless localization of logical and assignment (&&=) at - line 43.
1393 Useless localization of logical or assignment (||=) at - line 44.
1394 Useless localization of defined or assignment (//=) at - line 45.
1395 Useless localization of substr at - line 48.
1396 Useless localization of match position at - line 49.
1397 Useless localization of vec at - line 50.
1398 ########
1399 # op.c
1400 my $x1 if 0;
1401 my @x2 if 0;
1402 my %x3 if 0;
1403 my ($x4) if 0;
1404 my ($x5,@x6, %x7) if 0;
1405 0 && my $z1;
1406 0 && my (%z2);
1407 # these shouldn't warn
1408 our $x if 0;
1409 our $x unless 0;
1410 if (0) { my $w1 }
1411 if (my $w2) { $a=1 }
1412 if ($a && (my $w3 = 1)) {$a = 2}
1413
1414 EXPECT
1415 Deprecated use of my() in false conditional at - line 2.
1416 Deprecated use of my() in false conditional at - line 3.
1417 Deprecated use of my() in false conditional at - line 4.
1418 Deprecated use of my() in false conditional at - line 5.
1419 Deprecated use of my() in false conditional at - line 6.
1420 Deprecated use of my() in false conditional at - line 7.
1421 Deprecated use of my() in false conditional at - line 8.
1422 ########
1423 # op.c
1424 $[ = 1;
1425 ($[) = 1;
1426 use warnings 'deprecated';
1427 $[ = 2;
1428 ($[) = 2;
1429 no warnings 'deprecated';
1430 $[ = 3;
1431 ($[) = 3;
1432 EXPECT
1433 Use of assignment to $[ is deprecated at - line 2.
1434 Use of assignment to $[ is deprecated at - line 3.
1435 Use of assignment to $[ is deprecated at - line 5.
1436 Use of assignment to $[ is deprecated at - line 6.
1437 ########
1438 # op.c
1439 use warnings 'void';
1440 @x = split /y/, "z";
1441 $x = split /y/, "z";
1442      split /y/, "z";
1443 no warnings 'void';
1444 @x = split /y/, "z";
1445 $x = split /y/, "z";
1446      split /y/, "z";
1447 EXPECT
1448 Useless use of split in void context at - line 5.
1449 ########
1450 # op.c
1451 use warnings 'redefine' ;
1452 use utf8;
1453 use open qw( :utf8 :std );
1454 sub frèd {}
1455 sub frèd {}
1456 no warnings 'redefine' ;
1457 sub frèd {}
1458 EXPECT
1459 Subroutine frèd redefined at - line 6.
1460 ########
1461 # op.c
1462 use warnings 'redefine' ;
1463 use utf8;
1464 use open qw( :utf8 :std );
1465 sub frèd () { 1 }
1466 sub frèd () { 1 }
1467 no warnings 'redefine' ;
1468 sub frèd () { 1 }
1469 EXPECT
1470 Constant subroutine frèd redefined at - line 6.
1471 ########
1472 # op.c
1473 use utf8;
1474 use open qw( :utf8 :std );
1475 sub frèd () { 1 }
1476 sub frèd () { 2 }
1477 EXPECT
1478 Constant subroutine frèd redefined at - line 5.
1479 ########
1480 # op.c
1481 use utf8;
1482 use open qw( :utf8 :std );
1483 sub frèd () { 1 }
1484 *frèd = sub () { 2 };
1485 EXPECT
1486 Constant subroutine main::frèd redefined at - line 5.
1487 ########
1488 # op.c
1489 use warnings 'redefine' ;
1490 use utf8;
1491 use open qw( :utf8 :std );
1492 sub ᚠርƊ {}
1493 sub ᚠርƊ {}
1494 no warnings 'redefine' ;
1495 sub ᚠርƊ {}
1496 EXPECT
1497 Subroutine ᚠርƊ redefined at - line 6.
1498 ########
1499 # op.c
1500 use warnings 'redefine' ;
1501 use utf8;
1502 use open qw( :utf8 :std );
1503 sub ᚠርƊ () { 1 }
1504 sub ᚠርƊ () { 1 }
1505 no warnings 'redefine' ;
1506 sub ᚠርƊ () { 1 }
1507 EXPECT
1508 Constant subroutine ᚠርƊ redefined at - line 6.
1509 ########
1510 # op.c
1511 use utf8;
1512 use open qw( :utf8 :std );
1513 sub ᚠርƊ () { 1 }
1514 sub ᚠርƊ () { 2 }
1515 EXPECT
1516 Constant subroutine ᚠርƊ redefined at - line 5.
1517 ########
1518 # op.c
1519 use utf8;
1520 use open qw( :utf8 :std );
1521 sub ᚠርƊ () { 1 }
1522 *ᚠርƊ = sub () { 2 };
1523 EXPECT
1524 Constant subroutine main::ᚠርƊ redefined at - line 5.
1525 ########
1526 # OPTION regex
1527 sub DynaLoader::dl_error {};
1528 use warnings;
1529 # We're testing that the warnings report the same line number:
1530 eval <<'EOC' or die $@;
1531 {
1532     DynaLoader::boot_DynaLoader("DynaLoader");
1533 }
1534 EOC
1535 eval <<'EOC' or die $@;
1536 BEGIN {
1537     DynaLoader::boot_DynaLoader("DynaLoader");
1538 }
1539 1
1540 EOC
1541 EXPECT
1542 OPTION regex
1543 \ASubroutine DynaLoader::dl_error redefined at \(eval 1\) line 2\.
1544 ?(?s).*
1545 Subroutine DynaLoader::dl_error redefined at \(eval 2\) line 2\.
1546 ########