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