Overhaul the semantics of the warning
[p5sagit/p5-mst-13.2.git] / t / lib / warnings / op
1   op.c          AOK
2
3      Found = in conditional, should be ==
4         1 if $a = 1 ;
5
6      Use of implicit split to @_ is deprecated
7         split ;
8
9      Use of implicit split to @_ is deprecated
10         $a = split ;
11
12      Useless use of time in void context
13      Useless use of a variable in void context
14      Useless use of a constant in void context
15         time ;
16         $a ;
17         "abc"
18
19      Useless use of sort in scalar context
20         my $x = sort (2,1,3);
21
22      Applying %s to %s will act on scalar(%s)
23         my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
24         @a =~ /abc/ ;
25         @a =~ s/a/b/ ;
26         @a =~ tr/a/b/ ;
27         @$b =~ /abc/ ;
28         @$b =~ s/a/b/ ;
29         @$b =~ tr/a/b/ ;
30         %a =~ /abc/ ;
31         %a =~ s/a/b/ ;
32         %a =~ tr/a/b/ ;
33         %$c =~ /abc/ ;
34         %$c =~ s/a/b/ ;
35         %$c =~ tr/a/b/ ;
36
37
38      Parentheses missing around "my" list at -e line 1.
39        my $a, $b = (1,2);
40  
41      Parentheses missing around "local" list at -e line 1.
42        local $a, $b = (1,2);
43  
44      Bareword found in conditional at -e line 1.
45        use warnings 'bareword'; my $x = print(ABC || 1);
46  
47      Value of %s may be \"0\"; use \"defined\" 
48         $x = 1 if $x = <FH> ;
49         $x = 1 while $x = <FH> ;
50
51      Subroutine fred redefined at -e line 1.
52        sub fred{1;} sub fred{1;}
53  
54      Constant subroutine %s redefined 
55         sub fred() {1;} sub fred() {1;}
56  
57      Format FRED redefined at /tmp/x line 5.
58        format FRED =
59        .
60        format FRED =
61        .
62  
63      Array @%s missing the @ in argument %d of %s() 
64         push fred ;
65  
66      Hash %%%s missing the %% in argument %d of %s() 
67         keys joe ;
68  
69      Statement unlikely to be reached
70         (Maybe you meant system() when you said exec()?
71         exec "true" ; my $a
72
73      defined(@array) is deprecated
74         (Maybe you should just omit the defined()?)
75         my @a ; defined @a ;
76         defined (@a = (1,2,3)) ;
77
78      defined(%hash) is deprecated
79         (Maybe you should just omit the defined()?)
80         my %h ; defined %h ;
81     
82      /---/ should probably be written as "---"
83         join(/---/, @foo);
84
85     %s() called too early to check prototype            [Perl_peep]
86         fred() ; sub fred ($$) {}
87
88
89     Package `%s' not found (did you use the incorrect case?)
90
91     Use of /g modifier is meaningless in split
92
93     Possible precedence problem on bitwise %c operator  [Perl_ck_bitop]
94
95     Mandatory Warnings 
96     ------------------
97     Prototype mismatch:         [cv_ckproto]
98         sub fred() ;
99         sub fred($) {}
100
101     Runaway prototype           [newSUB]        TODO
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 no warnings 'syntax' ;
110 1 if $a = 1 ;
111 EXPECT
112 Found = in conditional, should be == at - line 3.
113 ########
114 # op.c
115 use warnings 'deprecated' ;
116 split ;
117 no warnings 'deprecated' ;
118 split ;
119 EXPECT
120 Use of implicit split to @_ is deprecated at - line 3.
121 ########
122 # op.c
123 use warnings 'deprecated' ;
124 $a = split ;
125 no warnings 'deprecated' ;
126 $a = split ;
127 EXPECT
128 Use of implicit split to @_ is deprecated at - line 3.
129 ########
130 # op.c
131 use warnings 'deprecated';
132 my (@foo, %foo);
133 %main::foo->{"bar"};
134 %foo->{"bar"};
135 @main::foo->[23];
136 @foo->[23];
137 $main::foo = {}; %$main::foo->{"bar"};
138 $foo = {}; %$foo->{"bar"};
139 $main::foo = []; @$main::foo->[34];
140 $foo = []; @$foo->[34];
141 no warnings 'deprecated';
142 %main::foo->{"bar"};
143 %foo->{"bar"};
144 @main::foo->[23];
145 @foo->[23];
146 $main::foo = {}; %$main::foo->{"bar"};
147 $foo = {}; %$foo->{"bar"};
148 $main::foo = []; @$main::foo->[34];
149 $foo = []; @$foo->[34];
150 EXPECT
151 Using a hash as a reference is deprecated at - line 4.
152 Using a hash as a reference is deprecated at - line 5.
153 Using an array as a reference is deprecated at - line 6.
154 Using an array as a reference is deprecated at - line 7.
155 Using a hash as a reference is deprecated at - line 8.
156 Using a hash as a reference is deprecated at - line 9.
157 Using an array as a reference is deprecated at - line 10.
158 Using an array as a reference is deprecated at - line 11.
159 ########
160 # op.c
161 use warnings 'void' ; close STDIN ;
162 1 x 3 ;                 # OP_REPEAT
163                         # OP_GVSV
164 wantarray ;             # OP_WANTARRAY
165                         # OP_GV
166                         # OP_PADSV
167                         # OP_PADAV
168                         # OP_PADHV
169                         # OP_PADANY
170                         # OP_AV2ARYLEN
171 ref ;                   # OP_REF
172 \@a ;                   # OP_REFGEN
173 \$a ;                   # OP_SREFGEN
174 defined $a ;            # OP_DEFINED
175 hex $a ;                # OP_HEX
176 oct $a ;                # OP_OCT
177 length $a ;             # OP_LENGTH
178 substr $a,1 ;           # OP_SUBSTR
179 vec $a,1,2 ;            # OP_VEC
180 index $a,1,2 ;          # OP_INDEX
181 rindex $a,1,2 ;         # OP_RINDEX
182 sprintf $a ;            # OP_SPRINTF
183 $a[0] ;                 # OP_AELEM
184                         # OP_AELEMFAST
185 @a[0] ;                 # OP_ASLICE
186 #values %a ;            # OP_VALUES
187 #keys %a ;              # OP_KEYS
188 $a{0} ;                 # OP_HELEM
189 @a{0} ;                 # OP_HSLICE
190 unpack "a", "a" ;       # OP_UNPACK
191 pack $a,"" ;            # OP_PACK
192 join "" ;               # OP_JOIN
193 (@a)[0,1] ;             # OP_LSLICE
194                         # OP_ANONLIST
195                         # OP_ANONHASH
196 sort(1,2) ;             # OP_SORT
197 reverse(1,2) ;          # OP_REVERSE
198                         # OP_RANGE
199                         # OP_FLIP
200 (1 ..2) ;               # OP_FLOP
201 caller ;                # OP_CALLER
202 fileno STDIN ;          # OP_FILENO
203 eof STDIN ;             # OP_EOF
204 tell STDIN ;            # OP_TELL
205 readlink 1;             # OP_READLINK
206 time ;                  # OP_TIME
207 localtime ;             # OP_LOCALTIME
208 gmtime ;                # OP_GMTIME
209 eval { getgrnam 1 };    # OP_GGRNAM
210 eval { getgrgid 1 };    # OP_GGRGID
211 eval { getpwnam 1 };    # OP_GPWNAM
212 eval { getpwuid 1 };    # OP_GPWUID
213 prototype "foo";        # OP_PROTOTYPE
214 EXPECT
215 Useless use of repeat (x) in void context at - line 3.
216 Useless use of wantarray in void context at - line 5.
217 Useless use of reference-type operator in void context at - line 12.
218 Useless use of reference constructor in void context at - line 13.
219 Useless use of single ref constructor in void context at - line 14.
220 Useless use of defined operator in void context at - line 15.
221 Useless use of hex in void context at - line 16.
222 Useless use of oct in void context at - line 17.
223 Useless use of length in void context at - line 18.
224 Useless use of substr in void context at - line 19.
225 Useless use of vec in void context at - line 20.
226 Useless use of index in void context at - line 21.
227 Useless use of rindex in void context at - line 22.
228 Useless use of sprintf in void context at - line 23.
229 Useless use of array element in void context at - line 24.
230 Useless use of array slice in void context at - line 26.
231 Useless use of hash element in void context at - line 29.
232 Useless use of hash slice in void context at - line 30.
233 Useless use of unpack in void context at - line 31.
234 Useless use of pack in void context at - line 32.
235 Useless use of join or string in void context at - line 33.
236 Useless use of list slice in void context at - line 34.
237 Useless use of sort in void context at - line 37.
238 Useless use of reverse in void context at - line 38.
239 Useless use of range (or flop) in void context at - line 41.
240 Useless use of caller in void context at - line 42.
241 Useless use of fileno in void context at - line 43.
242 Useless use of eof in void context at - line 44.
243 Useless use of tell in void context at - line 45.
244 Useless use of readlink in void context at - line 46.
245 Useless use of time in void context at - line 47.
246 Useless use of localtime in void context at - line 48.
247 Useless use of gmtime in void context at - line 49.
248 Useless use of getgrnam in void context at - line 50.
249 Useless use of getgrgid in void context at - line 51.
250 Useless use of getpwnam in void context at - line 52.
251 Useless use of getpwuid in void context at - line 53.
252 Useless use of subroutine prototype in void context at - line 54.
253 ########
254 # op.c
255 use warnings 'void' ; close STDIN ;
256 my $x = sort (2,1,3);
257 no warnings 'void' ;
258 $x = sort (2,1,3);
259 EXPECT
260 Useless use of sort in scalar context at - line 3.
261 ########
262 # op.c
263 no warnings 'void' ; close STDIN ;
264 1 x 3 ;                 # OP_REPEAT
265                         # OP_GVSV
266 wantarray ;             # OP_WANTARRAY
267                         # OP_GV
268                         # OP_PADSV
269                         # OP_PADAV
270                         # OP_PADHV
271                         # OP_PADANY
272                         # OP_AV2ARYLEN
273 ref ;                   # OP_REF
274 \@a ;                   # OP_REFGEN
275 \$a ;                   # OP_SREFGEN
276 defined $a ;            # OP_DEFINED
277 hex $a ;                # OP_HEX
278 oct $a ;                # OP_OCT
279 length $a ;             # OP_LENGTH
280 substr $a,1 ;           # OP_SUBSTR
281 vec $a,1,2 ;            # OP_VEC
282 index $a,1,2 ;          # OP_INDEX
283 rindex $a,1,2 ;         # OP_RINDEX
284 sprintf $a ;            # OP_SPRINTF
285 $a[0] ;                 # OP_AELEM
286                         # OP_AELEMFAST
287 @a[0] ;                 # OP_ASLICE
288 #values %a ;            # OP_VALUES
289 #keys %a ;              # OP_KEYS
290 $a{0} ;                 # OP_HELEM
291 @a{0} ;                 # OP_HSLICE
292 unpack "a", "a" ;       # OP_UNPACK
293 pack $a,"" ;            # OP_PACK
294 join "" ;               # OP_JOIN
295 (@a)[0,1] ;             # OP_LSLICE
296                         # OP_ANONLIST
297                         # OP_ANONHASH
298 sort(1,2) ;             # OP_SORT
299 reverse(1,2) ;          # OP_REVERSE
300                         # OP_RANGE
301                         # OP_FLIP
302 (1 ..2) ;               # OP_FLOP
303 caller ;                # OP_CALLER
304 fileno STDIN ;          # OP_FILENO
305 eof STDIN ;             # OP_EOF
306 tell STDIN ;            # OP_TELL
307 readlink 1;             # OP_READLINK
308 time ;                  # OP_TIME
309 localtime ;             # OP_LOCALTIME
310 gmtime ;                # OP_GMTIME
311 eval { getgrnam 1 };    # OP_GGRNAM
312 eval { getgrgid 1 };    # OP_GGRGID
313 eval { getpwnam 1 };    # OP_GPWNAM
314 eval { getpwuid 1 };    # OP_GPWUID
315 prototype "foo";        # OP_PROTOTYPE
316 EXPECT
317 ########
318 # op.c
319 use warnings 'void' ;
320 for (@{[0]}) { "$_" }           # check warning isn't duplicated
321 no warnings 'void' ;
322 for (@{[0]}) { "$_" }           # check warning isn't duplicated
323 EXPECT
324 Useless use of string in void context at - line 3.
325 ########
326 # op.c
327 use warnings 'void' ;
328 use Config ;
329 BEGIN {
330     if ( ! $Config{d_telldir}) {
331         print <<EOM ;
332 SKIPPED
333 # telldir not present
334 EOM
335         exit 
336     }
337 }
338 telldir 1 ;             # OP_TELLDIR
339 no warnings 'void' ;
340 telldir 1 ;             # OP_TELLDIR
341 EXPECT
342 Useless use of telldir in void context at - line 13.
343 ########
344 # op.c
345 use warnings 'void' ;
346 use Config ;
347 BEGIN {
348     if ( ! $Config{d_getppid}) {
349         print <<EOM ;
350 SKIPPED
351 # getppid not present
352 EOM
353         exit 
354     }
355 }
356 getppid ;               # OP_GETPPID
357 no warnings 'void' ;
358 getppid ;               # OP_GETPPID
359 EXPECT
360 Useless use of getppid in void context at - line 13.
361 ########
362 # op.c
363 use warnings 'void' ;
364 use Config ;
365 BEGIN {
366     if ( ! $Config{d_getpgrp}) {
367         print <<EOM ;
368 SKIPPED
369 # getpgrp not present
370 EOM
371         exit 
372     }
373 }
374 getpgrp ;               # OP_GETPGRP
375 no warnings 'void' ;
376 getpgrp ;               # OP_GETPGRP
377 EXPECT
378 Useless use of getpgrp in void context at - line 13.
379 ########
380 # op.c
381 use warnings 'void' ;
382 use Config ;
383 BEGIN {
384     if ( ! $Config{d_times}) {
385         print <<EOM ;
386 SKIPPED
387 # times not present
388 EOM
389         exit 
390     }
391 }
392 times ;                 # OP_TMS
393 no warnings 'void' ;
394 times ;                 # OP_TMS
395 EXPECT
396 Useless use of times in void context at - line 13.
397 ########
398 # op.c
399 use warnings 'void' ;
400 use Config ;
401 BEGIN {
402     if ( ! $Config{d_getprior} or $^O eq 'os2') { # Locks before fixpak22
403         print <<EOM ;
404 SKIPPED
405 # getpriority not present
406 EOM
407         exit 
408     }
409 }
410 getpriority 1,2;        # OP_GETPRIORITY
411 no warnings 'void' ;
412 getpriority 1,2;        # OP_GETPRIORITY
413 EXPECT
414 Useless use of getpriority in void context at - line 13.
415 ########
416 # op.c
417 use warnings 'void' ;
418 use Config ;
419 BEGIN {
420     if ( ! $Config{d_getlogin}) {
421         print <<EOM ;
422 SKIPPED
423 # getlogin not present
424 EOM
425         exit 
426     }
427 }
428 getlogin ;                      # OP_GETLOGIN
429 no warnings 'void' ;
430 getlogin ;                      # OP_GETLOGIN
431 EXPECT
432 Useless use of getlogin in void context at - line 13.
433 ########
434 # op.c
435 use warnings 'void' ;
436 use Config ; BEGIN {
437 if ( ! $Config{d_socket}) {
438     print <<EOM ;
439 SKIPPED
440 # getsockname not present
441 # getpeername not present
442 # gethostbyname not present
443 # gethostbyaddr not present
444 # gethostent not present
445 # getnetbyname not present
446 # getnetbyaddr not present
447 # getnetent not present
448 # getprotobyname not present
449 # getprotobynumber not present
450 # getprotoent not present
451 # getservbyname not present
452 # getservbyport not present
453 # getservent not present
454 EOM
455     exit 
456 } }
457 getsockname STDIN ;     # OP_GETSOCKNAME
458 getpeername STDIN ;     # OP_GETPEERNAME
459 gethostbyname 1 ;       # OP_GHBYNAME
460 gethostbyaddr 1,2;      # OP_GHBYADDR
461 gethostent ;            # OP_GHOSTENT
462 getnetbyname 1 ;        # OP_GNBYNAME
463 getnetbyaddr 1,2 ;      # OP_GNBYADDR
464 getnetent ;             # OP_GNETENT
465 getprotobyname 1;       # OP_GPBYNAME
466 getprotobynumber 1;     # OP_GPBYNUMBER
467 getprotoent ;           # OP_GPROTOENT
468 getservbyname 1,2;      # OP_GSBYNAME
469 getservbyport 1,2;      # OP_GSBYPORT
470 getservent ;            # OP_GSERVENT
471
472 no warnings 'void' ;
473 getsockname STDIN ;     # OP_GETSOCKNAME
474 getpeername STDIN ;     # OP_GETPEERNAME
475 gethostbyname 1 ;       # OP_GHBYNAME
476 gethostbyaddr 1,2;      # OP_GHBYADDR
477 gethostent ;            # OP_GHOSTENT
478 getnetbyname 1 ;        # OP_GNBYNAME
479 getnetbyaddr 1,2 ;      # OP_GNBYADDR
480 getnetent ;             # OP_GNETENT
481 getprotobyname 1;       # OP_GPBYNAME
482 getprotobynumber 1;     # OP_GPBYNUMBER
483 getprotoent ;           # OP_GPROTOENT
484 getservbyname 1,2;      # OP_GSBYNAME
485 getservbyport 1,2;      # OP_GSBYPORT
486 getservent ;            # OP_GSERVENT
487 INIT {
488    # some functions may not be there, so we exit without running
489    exit;
490 }
491 EXPECT
492 Useless use of getsockname in void context at - line 24.
493 Useless use of getpeername in void context at - line 25.
494 Useless use of gethostbyname in void context at - line 26.
495 Useless use of gethostbyaddr in void context at - line 27.
496 Useless use of gethostent in void context at - line 28.
497 Useless use of getnetbyname in void context at - line 29.
498 Useless use of getnetbyaddr in void context at - line 30.
499 Useless use of getnetent in void context at - line 31.
500 Useless use of getprotobyname in void context at - line 32.
501 Useless use of getprotobynumber in void context at - line 33.
502 Useless use of getprotoent in void context at - line 34.
503 Useless use of getservbyname in void context at - line 35.
504 Useless use of getservbyport in void context at - line 36.
505 Useless use of getservent in void context at - line 37.
506 ########
507 # op.c
508 use warnings 'void' ;
509 *a ; # OP_RV2GV
510 $a ; # OP_RV2SV
511 @a ; # OP_RV2AV
512 %a ; # OP_RV2HV
513 no warnings 'void' ;
514 *a ; # OP_RV2GV
515 $a ; # OP_RV2SV
516 @a ; # OP_RV2AV
517 %a ; # OP_RV2HV
518 EXPECT
519 Useless use of a variable in void context at - line 3.
520 Useless use of a variable in void context at - line 4.
521 Useless use of a variable in void context at - line 5.
522 Useless use of a variable in void context at - line 6.
523 ########
524 # op.c
525 use warnings 'void' ;
526 "abc"; # OP_CONST
527 7 ; # OP_CONST
528 5 || print "bad\n";     # test OPpCONST_SHORTCIRCUIT
529 use constant U => undef;
530 print "boo\n" if U;     # test OPpCONST_SHORTCIRCUIT
531 no warnings 'void' ;
532 "abc"; # OP_CONST
533 7 ; # OP_CONST
534 EXPECT
535 Useless use of a constant in void context at - line 3.
536 Useless use of a constant in void context at - line 4.
537 ########
538 # op.c
539 #
540 use warnings 'misc' ;
541 my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
542 @a =~ /abc/ ;
543 @a =~ s/a/b/ ;
544 @a =~ tr/a/b/ ;
545 @$b =~ /abc/ ;
546 @$b =~ s/a/b/ ;
547 @$b =~ tr/a/b/ ;
548 %a =~ /abc/ ;
549 %a =~ s/a/b/ ;
550 %a =~ tr/a/b/ ;
551 %$c =~ /abc/ ;
552 %$c =~ s/a/b/ ;
553 %$c =~ tr/a/b/ ;
554 {
555 no warnings 'misc' ;
556 my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
557 @a =~ /abc/ ;
558 @a =~ s/a/b/ ;
559 @a =~ tr/a/b/ ;
560 @$b =~ /abc/ ;
561 @$b =~ s/a/b/ ;
562 @$b =~ tr/a/b/ ;
563 %a =~ /abc/ ;
564 %a =~ s/a/b/ ;
565 %a =~ tr/a/b/ ;
566 %$c =~ /abc/ ;
567 %$c =~ s/a/b/ ;
568 %$c =~ tr/a/b/ ;
569 }
570 EXPECT
571 Applying pattern match (m//) to @array will act on scalar(@array) at - line 5.
572 Applying substitution (s///) to @array will act on scalar(@array) at - line 6.
573 Applying transliteration (tr///) to @array will act on scalar(@array) at - line 7.
574 Applying pattern match (m//) to @array will act on scalar(@array) at - line 8.
575 Applying substitution (s///) to @array will act on scalar(@array) at - line 9.
576 Applying transliteration (tr///) to @array will act on scalar(@array) at - line 10.
577 Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 11.
578 Applying substitution (s///) to %hash will act on scalar(%hash) at - line 12.
579 Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 13.
580 Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 14.
581 Applying substitution (s///) to %hash will act on scalar(%hash) at - line 15.
582 Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 16.
583 Can't modify private array in substitution (s///) at - line 6, near "s/a/b/ ;"
584 BEGIN not safe after errors--compilation aborted at - line 18.
585 ########
586 # op.c
587 use warnings 'parenthesis' ;
588 my $a, $b = (1,2);
589 my @foo,%bar,   $quux; # there's a TAB here
590 my $x, $y or print;
591 no warnings 'parenthesis' ;
592 my $c, $d = (1,2);
593 EXPECT
594 Parentheses missing around "my" list at - line 3.
595 Parentheses missing around "my" list at - line 4.
596 ########
597 # op.c
598 use warnings 'parenthesis' ;
599 our $a, $b = (1,2);
600 no warnings 'parenthesis' ;
601 our $c, $d = (1,2);
602 EXPECT
603 Parentheses missing around "our" list at - line 3.
604 ########
605 # op.c
606 use warnings 'parenthesis' ;
607 local $a, $b = (1,2);
608 local *f, *g;
609 no warnings 'parenthesis' ;
610 local $c, $d = (1,2);
611 EXPECT
612 Parentheses missing around "local" list at - line 3.
613 Parentheses missing around "local" list at - line 4.
614 ########
615 # op.c
616 use warnings 'bareword' ;
617 print (ABC || 1) ;
618 no warnings 'bareword' ;
619 print (ABC || 1) ;
620 EXPECT
621 Bareword found in conditional at - line 3.
622 ########
623 --FILE-- abc
624
625 --FILE--
626 # op.c
627 use warnings 'misc' ;
628 open FH, "<abc" ;
629 $x = 1 if $x = <FH> ;
630 no warnings 'misc' ;
631 $x = 1 if $x = <FH> ;
632 EXPECT
633 Value of <HANDLE> construct can be "0"; test with defined() at - line 4.
634 ########
635 # op.c
636 use warnings 'misc' ;
637 opendir FH, "." ;
638 $x = 1 if $x = readdir FH ;
639 no warnings 'misc' ;
640 $x = 1 if $x = readdir FH ;
641 closedir FH ;
642 EXPECT
643 Value of readdir() operator can be "0"; test with defined() at - line 4.
644 ########
645 # op.c
646 use warnings 'misc' ;
647 $x = 1 if $x = <*> ;
648 no warnings 'misc' ;
649 $x = 1 if $x = <*> ;
650 EXPECT
651 Value of glob construct can be "0"; test with defined() at - line 3.
652 ########
653 # op.c
654 use warnings 'misc' ;
655 %a = (1,2,3,4) ;
656 $x = 1 if $x = each %a ;
657 no warnings 'misc' ;
658 $x = 1 if $x = each %a ;
659 EXPECT
660 Value of each() operator can be "0"; test with defined() at - line 4.
661 ########
662 # op.c
663 use warnings 'misc' ;
664 $x = 1 while $x = <*> and 0 ;
665 no warnings 'misc' ;
666 $x = 1 while $x = <*> and 0 ;
667 EXPECT
668 Value of glob construct can be "0"; test with defined() at - line 3.
669 ########
670 # op.c
671 use warnings 'misc' ;
672 opendir FH, "." ;
673 $x = 1 while $x = readdir FH and 0 ;
674 no warnings 'misc' ;
675 $x = 1 while $x = readdir FH and 0 ;
676 closedir FH ;
677 EXPECT
678 Value of readdir() operator can be "0"; test with defined() at - line 4.
679 ########
680 # op.c
681 use warnings 'misc';
682 open FH, "<abc";
683 $_ = <FH> err $_ = 1;
684 ($_ = <FH>) // ($_ = 1);
685 opendir DH, ".";
686 $_ = readdir DH err $_ = 1;
687 $_ = <*> err $_ = 1;
688 %a = (1,2,3,4) ;
689 $_ = each %a err $_ = 1;
690 EXPECT
691 ########
692 # op.c
693 use warnings 'redefine' ;
694 sub fred {}
695 sub fred {}
696 no warnings 'redefine' ;
697 sub fred {}
698 EXPECT
699 Subroutine fred redefined at - line 4.
700 ########
701 # op.c
702 use warnings 'redefine' ;
703 sub fred () { 1 }
704 sub fred () { 1 }
705 no warnings 'redefine' ;
706 sub fred () { 1 }
707 EXPECT
708 Constant subroutine fred redefined at - line 4.
709 ########
710 # op.c
711 no warnings 'redefine' ;
712 sub fred () { 1 }
713 sub fred () { 2 }
714 EXPECT
715 Constant subroutine fred redefined at - line 4.
716 ########
717 # op.c
718 no warnings 'redefine' ;
719 sub fred () { 1 }
720 *fred = sub () { 2 };
721 EXPECT
722 Constant subroutine main::fred redefined at - line 4.
723 ########
724 # op.c
725 use warnings 'redefine' ;
726 format FRED =
727 .
728 format FRED =
729 .
730 no warnings 'redefine' ;
731 format FRED =
732 .
733 EXPECT
734 Format FRED redefined at - line 5.
735 ########
736 # op.c
737 use warnings 'deprecated' ;
738 push FRED;
739 no warnings 'deprecated' ;
740 push FRED;
741 EXPECT
742 Array @FRED missing the @ in argument 1 of push() at - line 3.
743 ########
744 # op.c
745 use warnings 'deprecated' ;
746 @a = keys FRED ;
747 no warnings 'deprecated' ;
748 @a = keys FRED ;
749 EXPECT
750 Hash %FRED missing the % in argument 1 of keys() at - line 3.
751 ########
752 # op.c
753 BEGIN {
754     if ($^O eq 'MacOS') {
755         print <<EOM;
756 SKIPPED
757 # no exec on Mac OS
758 EOM
759         exit;
760     }
761 }
762 use warnings 'syntax' ;
763 exec "$^X -e 1" ; 
764 my $a
765 EXPECT
766 Statement unlikely to be reached at - line 13.
767         (Maybe you meant system() when you said exec()?)
768 ########
769 # op.c
770 use warnings 'deprecated' ;
771 my @a; defined(@a);
772 EXPECT
773 defined(@array) is deprecated at - line 3.
774         (Maybe you should just omit the defined()?)
775 ########
776 # op.c
777 use warnings 'deprecated' ;
778 defined(@a = (1,2,3));
779 EXPECT
780 defined(@array) is deprecated at - line 3.
781         (Maybe you should just omit the defined()?)
782 ########
783 # op.c
784 use warnings 'deprecated' ;
785 my %h; defined(%h);
786 EXPECT
787 defined(%hash) is deprecated at - line 3.
788         (Maybe you should just omit the defined()?)
789 ########
790 # op.c
791 BEGIN {
792     if ($^O eq 'MacOS') {
793         print <<EOM;
794 SKIPPED
795 # no exec on Mac OS
796 EOM
797         exit;
798     }
799 }
800 no warnings 'syntax' ;
801 exec "$^X -e 1" ; 
802 my $a
803 EXPECT
804
805 ########
806 # op.c
807 sub fred();
808 sub fred($) {}
809 EXPECT
810 Prototype mismatch: sub main::fred () vs ($) at - line 3.
811 ########
812 # op.c
813 $^W = 0 ;
814 sub fred() ;
815 sub fred($) {}
816 {
817     no warnings 'prototype' ;
818     sub Fred() ;
819     sub Fred($) {}
820     use warnings 'prototype' ;
821     sub freD() ;
822     sub freD($) {}
823 }
824 sub FRED() ;
825 sub FRED($) {}
826 EXPECT
827 Prototype mismatch: sub main::fred () vs ($) at - line 4.
828 Prototype mismatch: sub main::freD () vs ($) at - line 11.
829 Prototype mismatch: sub main::FRED () vs ($) at - line 14.
830 ########
831 # op.c
832 use warnings 'syntax' ;
833 join /---/, 'x', 'y', 'z';
834 EXPECT
835 /---/ should probably be written as "---" at - line 3.
836 ########
837 # op.c [Perl_peep]
838 use warnings 'prototype' ;
839 fred() ; 
840 sub fred ($$) {}
841 no warnings 'prototype' ;
842 joe() ; 
843 sub joe ($$) {}
844 EXPECT
845 main::fred() called too early to check prototype at - line 3.
846 ########
847 # op.c [Perl_newATTRSUB]
848 --FILE-- abc.pm
849 use warnings 'void' ;
850 BEGIN { $| = 1; print "in begin\n"; }
851 CHECK { print "in check\n"; }
852 INIT { print "in init\n"; }
853 END { print "in end\n"; }
854 print "in mainline\n";
855 1;
856 --FILE--
857 use abc;
858 delete $INC{"abc.pm"};
859 require abc;
860 do "abc.pm";
861 EXPECT
862 in begin
863 in mainline
864 in check
865 in init
866 in begin
867 Too late to run CHECK block at abc.pm line 3.
868 Too late to run INIT block at abc.pm line 4.
869 in mainline
870 in begin
871 Too late to run CHECK block at abc.pm line 3.
872 Too late to run INIT block at abc.pm line 4.
873 in mainline
874 in end
875 in end
876 in end
877 ########
878 # op.c [Perl_newATTRSUB]
879 --FILE-- abc.pm
880 no warnings 'void' ;
881 BEGIN { $| = 1; print "in begin\n"; }
882 CHECK { print "in check\n"; }
883 INIT { print "in init\n"; }
884 END { print "in end\n"; }
885 print "in mainline\n";
886 1;
887 --FILE--
888 require abc;
889 do "abc.pm";
890 EXPECT
891 in begin
892 in mainline
893 in begin
894 in mainline
895 in end
896 in end
897 ########
898 # op.c
899 my @x;
900 use warnings 'syntax' ;
901 push(@x);
902 unshift(@x);
903 no warnings 'syntax' ;
904 push(@x);
905 unshift(@x);
906 EXPECT
907 Useless use of push with no values at - line 4.
908 Useless use of unshift with no values at - line 5.
909 ########
910 # op.c
911 # 20020401 mjd@plover.com at suggestion of jfriedl@yahoo.com
912 use warnings 'regexp';
913 split /blah/g, "blah";
914 no warnings 'regexp';
915 split /blah/g, "blah";
916 EXPECT
917 Use of /g modifier is meaningless in split at - line 4.
918 ########
919 # op.c
920 use warnings 'precedence';
921 $a = $b & $c == $d;
922 $a = $b ^ $c != $d;
923 $a = $b | $c > $d;
924 $a = $b < $c & $d;
925 $a = $b >= $c ^ $d;
926 $a = $b <= $c | $d;
927 $a = $b <=> $c & $d;
928 $a &= $b == $c; $a |= $b == $c; $a ^= $b == $c; # shouldn't warn
929 no warnings 'precedence';
930 $a = $b & $c == $d;
931 $a = $b ^ $c != $d;
932 $a = $b | $c > $d;
933 $a = $b < $c & $d;
934 $a = $b >= $c ^ $d;
935 $a = $b <= $c | $d;
936 $a = $b <=> $c & $d;
937 EXPECT
938 Possible precedence problem on bitwise & operator at - line 3.
939 Possible precedence problem on bitwise ^ operator at - line 4.
940 Possible precedence problem on bitwise | operator at - line 5.
941 Possible precedence problem on bitwise & operator at - line 6.
942 Possible precedence problem on bitwise ^ operator at - line 7.
943 Possible precedence problem on bitwise | operator at - line 8.
944 Possible precedence problem on bitwise & operator at - line 9.
945 ########
946 # op.c
947 use integer;
948 use warnings 'precedence';
949 $a = $b & $c == $d;
950 $a = $b ^ $c != $d;
951 $a = $b | $c > $d;
952 $a = $b < $c & $d;
953 $a = $b >= $c ^ $d;
954 $a = $b <= $c | $d;
955 $a = $b <=> $c & $d;
956 no warnings 'precedence';
957 $a = $b & $c == $d;
958 $a = $b ^ $c != $d;
959 $a = $b | $c > $d;
960 $a = $b < $c & $d;
961 $a = $b >= $c ^ $d;
962 $a = $b <= $c | $d;
963 $a = $b <=> $c & $d;
964 EXPECT
965 Possible precedence problem on bitwise & operator at - line 4.
966 Possible precedence problem on bitwise ^ operator at - line 5.
967 Possible precedence problem on bitwise | operator at - line 6.
968 Possible precedence problem on bitwise & operator at - line 7.
969 Possible precedence problem on bitwise ^ operator at - line 8.
970 Possible precedence problem on bitwise | operator at - line 9.
971 Possible precedence problem on bitwise & operator at - line 10.
972 ########
973 # op.c
974
975 # ok    => local() has desired effect;
976 # ignore=> local() silently ignored
977
978 use warnings 'syntax';
979
980 local(undef);           # OP_UNDEF              ignore
981 sub lval : lvalue {};
982 local(lval());          # OP_ENTERSUB
983 local($x **= 1);        # OP_POW
984 local($x *=  1);        # OP_MULTIPLY
985 local($x /=  1);        # OP_DIVIDE
986 local($x %=  1);        # OP_MODULO
987 local($x x=  1);        # OP_REPEAT
988 local($x +=  1);        # OP_ADD
989 local($x -=  1);        # OP_SUBTRACT
990 local($x .=  1);        # OP_CONCAT
991 local($x <<= 1);        # OP_LEFT_SHIFT
992 local($x >>= 1);        # OP_RIGHT_SHIFT
993 local($x &=  1);        # OP_BIT_AND
994 local($x ^=  1);        # OP_BIT_XOR
995 local($x |=  1);        # OP_BIT_OR
996 {
997     use integer;
998     local($x *= 1);     # OP_I_MULTIPLY
999     local($x /= 1);     # OP_I_DIVIDE
1000     local($x %= 1);     # OP_I_MODULO
1001     local($x += 1);     # OP_I_ADD
1002     local($x -= 1);     # OP_I_SUBTRACT
1003 }
1004 local($x?$y:$z) = 1;    # OP_COND_EXPR          ok
1005 # these two are fatal run-time errors instead
1006 #local(@$a);            # OP_RV2AV              ok
1007 #local(%$a);            # OP_RV2HV              ok
1008 local(*a);              # OP_RV2GV              ok
1009 local(@a[1,2]);         # OP_ASLICE             ok
1010 local(@a{1,2});         # OP_HSLICE             ok
1011 local(@a = (1,2));      # OP_AASSIGN
1012 local($$x);             # OP_RV2SV              ok
1013 local($#a);             # OP_AV2ARYLEN
1014 local($x =   1);        # OP_SASSIGN
1015 local($x &&= 1);        # OP_ANDASSIGN
1016 local($x ||= 1);        # OP_ORASSIGN
1017 local($x //= 1);        # OP_DORASSIGN
1018 local($a[0]);           # OP_AELEMFAST          ok
1019
1020 local(substr($x,0,1));  # OP_SUBSTR
1021 local(pos($x));         # OP_POS
1022 local(vec($x,0,1));     # OP_VEC
1023 local($a[$b]);          # OP_AELEM              ok
1024 local($a{$b});          # OP_HELEM              ok
1025
1026 no warnings 'syntax';
1027 EXPECT
1028 Useless localization of subroutine entry at - line 10.
1029 Useless localization of exponentiation (**) at - line 11.
1030 Useless localization of multiplication (*) at - line 12.
1031 Useless localization of division (/) at - line 13.
1032 Useless localization of modulus (%) at - line 14.
1033 Useless localization of repeat (x) at - line 15.
1034 Useless localization of addition (+) at - line 16.
1035 Useless localization of subtraction (-) at - line 17.
1036 Useless localization of concatenation (.) or string at - line 18.
1037 Useless localization of left bitshift (<<) at - line 19.
1038 Useless localization of right bitshift (>>) at - line 20.
1039 Useless localization of bitwise and (&) at - line 21.
1040 Useless localization of bitwise xor (^) at - line 22.
1041 Useless localization of bitwise or (|) at - line 23.
1042 Useless localization of integer multiplication (*) at - line 26.
1043 Useless localization of integer division (/) at - line 27.
1044 Useless localization of integer modulus (%) at - line 28.
1045 Useless localization of integer addition (+) at - line 29.
1046 Useless localization of integer subtraction (-) at - line 30.
1047 Useless localization of list assignment at - line 39.
1048 Useless localization of array length at - line 41.
1049 Useless localization of scalar assignment at - line 42.
1050 Useless localization of logical and assignment (&&=) at - line 43.
1051 Useless localization of logical or assignment (||=) at - line 44.
1052 Useless localization of defined or assignment (//=) at - line 45.
1053 Useless localization of substr at - line 48.
1054 Useless localization of match position at - line 49.
1055 Useless localization of vec at - line 50.
1056 ########
1057 # op.c
1058 use warnings 'deprecated';
1059 my $x1 if 0;
1060 my @x2 if 0;
1061 my %x3 if 0;
1062 my ($x4) if 0;
1063 my ($x5,@x6, %x7) if 0;
1064 0 && my $z1;
1065 0 && my (%z2);
1066 # these shouldn't warn
1067 our $x if 0;
1068 our $x unless 0;
1069 if (0) { my $w1 }
1070 if (my $w2) { $a=1 }
1071 if ($a && (my $w3 = 1)) {$a = 2}
1072
1073 EXPECT
1074 Deprecated use of my() in false conditional at - line 3.
1075 Deprecated use of my() in false conditional at - line 4.
1076 Deprecated use of my() in false conditional at - line 5.
1077 Deprecated use of my() in false conditional at - line 6.
1078 Deprecated use of my() in false conditional at - line 7.
1079 Deprecated use of my() in false conditional at - line 8.
1080 Deprecated use of my() in false conditional at - line 9.