This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
32f66dc5c1f6a45026a175da71a36360b74588ae
[perl5.git] / t / pragma / warn / op
1   op.c          AOK
2
3      "my" variable %s masks earlier declaration in same scope
4         my $x;
5         my $x ;
6
7      Variable "%s" may be unavailable 
8         sub x {
9             my $x;
10             sub y {
11                 $x
12             }
13         }
14
15      Variable "%s" will not stay shared 
16         sub x {
17             my $x;
18             sub y {
19                 sub { $x }
20             }
21         }
22
23      Found = in conditional, should be ==
24         1 if $a = 1 ;
25
26      Use of implicit split to @_ is deprecated
27         split ;
28
29      Use of implicit split to @_ is deprecated
30         $a = split ;
31
32      Useless use of time in void context
33      Useless use of a variable in void context
34      Useless use of a constant in void context
35         time ;
36         $a ;
37         "abc"
38
39      Applying %s to %s will act on scalar(%s)
40         my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
41         @a =~ /abc/ ;
42         @a =~ s/a/b/ ;
43         @a =~ tr/a/b/ ;
44         @$b =~ /abc/ ;
45         @$b =~ s/a/b/ ;
46         @$b =~ tr/a/b/ ;
47         %a =~ /abc/ ;
48         %a =~ s/a/b/ ;
49         %a =~ tr/a/b/ ;
50         %$c =~ /abc/ ;
51         %$c =~ s/a/b/ ;
52         %$c =~ tr/a/b/ ;
53
54
55      Parentheses missing around "my" list at -e line 1.
56        my $a, $b = (1,2);
57  
58      Parentheses missing around "local" list at -e line 1.
59        local $a, $b = (1,2);
60  
61      Bareword found in conditional at -e line 1.
62        use warnings 'bareword'; my $x = print(ABC || 1);
63  
64      Value of %s may be \"0\"; use \"defined\" 
65         $x = 1 if $x = <FH> ;
66         $x = 1 while $x = <FH> ;
67
68      Subroutine fred redefined at -e line 1.
69        sub fred{1;} sub fred{1;}
70  
71      Constant subroutine %s redefined 
72         sub fred() {1;} sub fred() {1;}
73  
74      Format FRED redefined at /tmp/x line 5.
75        format FRED =
76        .
77        format FRED =
78        .
79  
80      Array @%s missing the @ in argument %d of %s() 
81         push fred ;
82  
83      Hash %%%s missing the %% in argument %d of %s() 
84         keys joe ;
85  
86      Statement unlikely to be reached
87         (Maybe you meant system() when you said exec()?
88         exec "true" ; my $a
89
90      defined(@array) is deprecated
91         (Maybe you should just omit the defined()?)
92         my @a ; defined @a ;
93         defined (@a = (1,2,3)) ;
94
95      defined(%hash) is deprecated
96         (Maybe you should just omit the defined()?)
97         my %h ; defined %h ;
98     
99      /---/ should probably be written as "---"
100         join(/---/, @foo);
101
102     %s() called too early to check prototype            [Perl_peep]
103         fred() ; sub fred ($$) {}
104
105
106     Mandatory Warnings 
107     ------------------
108     Prototype mismatch:         [cv_ckproto]
109         sub fred() ;
110         sub fred($) {}
111
112     %s never introduced         [pad_leavemy]   TODO
113     Runaway prototype           [newSUB]        TODO
114     oops: oopsAV                [oopsAV]        TODO
115     oops: oopsHV                [oopsHV]        TODO
116     
117
118 __END__
119 # op.c
120 use warnings 'misc' ;
121 my $x ;
122 my $x ;
123 no warnings 'misc' ;
124 my $x ;
125 EXPECT
126 "my" variable $x masks earlier declaration in same scope at - line 4.
127 ########
128 # op.c
129 use warnings 'closure' ;
130 sub x {
131       my $x;
132       sub y {
133          $x
134       }
135    }
136 EXPECT
137 Variable "$x" will not stay shared at - line 7.
138 ########
139 # op.c
140 no warnings 'closure' ;
141 sub x {
142       my $x;
143       sub y {
144          $x
145       }
146    }
147 EXPECT
148
149 ########
150 # op.c
151 use warnings 'closure' ;
152 sub x {
153       our $x;
154       sub y {
155          $x
156       }
157    }
158 EXPECT
159
160 ########
161 # op.c
162 use warnings 'closure' ;
163 sub x {
164       my $x;
165       sub y {
166          sub { $x }
167       }
168    }
169 EXPECT
170 Variable "$x" may be unavailable at - line 6.
171 ########
172 # op.c
173 no warnings 'closure' ;
174 sub x {
175       my $x;
176       sub y {
177          sub { $x }
178       }
179    }
180 EXPECT
181
182 ########
183 # op.c
184 use warnings 'syntax' ;
185 1 if $a = 1 ;
186 no warnings 'syntax' ;
187 1 if $a = 1 ;
188 EXPECT
189 Found = in conditional, should be == at - line 3.
190 ########
191 # op.c
192 use warnings 'deprecated' ;
193 split ;
194 no warnings 'deprecated' ;
195 split ;
196 EXPECT
197 Use of implicit split to @_ is deprecated at - line 3.
198 ########
199 # op.c
200 use warnings 'deprecated' ;
201 $a = split ;
202 no warnings 'deprecated' ;
203 $a = split ;
204 EXPECT
205 Use of implicit split to @_ is deprecated at - line 3.
206 ########
207 # op.c
208 use warnings 'void' ; close STDIN ;
209 1 x 3 ;                 # OP_REPEAT
210                         # OP_GVSV
211 wantarray ;             # OP_WANTARRAY
212                         # OP_GV
213                         # OP_PADSV
214                         # OP_PADAV
215                         # OP_PADHV
216                         # OP_PADANY
217                         # OP_AV2ARYLEN
218 ref ;                   # OP_REF
219 \@a ;                   # OP_REFGEN
220 \$a ;                   # OP_SREFGEN
221 defined $a ;            # OP_DEFINED
222 hex $a ;                # OP_HEX
223 oct $a ;                # OP_OCT
224 length $a ;             # OP_LENGTH
225 substr $a,1 ;           # OP_SUBSTR
226 vec $a,1,2 ;            # OP_VEC
227 index $a,1,2 ;          # OP_INDEX
228 rindex $a,1,2 ;         # OP_RINDEX
229 sprintf $a ;            # OP_SPRINTF
230 $a[0] ;                 # OP_AELEM
231                         # OP_AELEMFAST
232 @a[0] ;                 # OP_ASLICE
233 #values %a ;            # OP_VALUES
234 #keys %a ;              # OP_KEYS
235 $a{0} ;                 # OP_HELEM
236 @a{0} ;                 # OP_HSLICE
237 unpack "a", "a" ;       # OP_UNPACK
238 pack $a,"" ;            # OP_PACK
239 join "" ;               # OP_JOIN
240 (@a)[0,1] ;             # OP_LSLICE
241                         # OP_ANONLIST
242                         # OP_ANONHASH
243 sort(1,2) ;             # OP_SORT
244 reverse(1,2) ;          # OP_REVERSE
245                         # OP_RANGE
246                         # OP_FLIP
247 (1 ..2) ;               # OP_FLOP
248 caller ;                # OP_CALLER
249 fileno STDIN ;          # OP_FILENO
250 eof STDIN ;             # OP_EOF
251 tell STDIN ;            # OP_TELL
252 readlink 1;             # OP_READLINK
253 time ;                  # OP_TIME
254 localtime ;             # OP_LOCALTIME
255 gmtime ;                # OP_GMTIME
256 eval { getgrnam 1 };    # OP_GGRNAM
257 eval { getgrgid 1 };    # OP_GGRGID
258 eval { getpwnam 1 };    # OP_GPWNAM
259 eval { getpwuid 1 };    # OP_GPWUID
260 EXPECT
261 Useless use of repeat (x) in void context at - line 3.
262 Useless use of wantarray in void context at - line 5.
263 Useless use of reference-type operator in void context at - line 12.
264 Useless use of reference constructor in void context at - line 13.
265 Useless use of single ref constructor in void context at - line 14.
266 Useless use of defined operator in void context at - line 15.
267 Useless use of hex in void context at - line 16.
268 Useless use of oct in void context at - line 17.
269 Useless use of length in void context at - line 18.
270 Useless use of substr in void context at - line 19.
271 Useless use of vec in void context at - line 20.
272 Useless use of index in void context at - line 21.
273 Useless use of rindex in void context at - line 22.
274 Useless use of sprintf in void context at - line 23.
275 Useless use of array element in void context at - line 24.
276 Useless use of array slice in void context at - line 26.
277 Useless use of hash element in void context at - line 29.
278 Useless use of hash slice in void context at - line 30.
279 Useless use of unpack in void context at - line 31.
280 Useless use of pack in void context at - line 32.
281 Useless use of join in void context at - line 33.
282 Useless use of list slice in void context at - line 34.
283 Useless use of sort in void context at - line 37.
284 Useless use of reverse in void context at - line 38.
285 Useless use of range (or flop) in void context at - line 41.
286 Useless use of caller in void context at - line 42.
287 Useless use of fileno in void context at - line 43.
288 Useless use of eof in void context at - line 44.
289 Useless use of tell in void context at - line 45.
290 Useless use of readlink in void context at - line 46.
291 Useless use of time in void context at - line 47.
292 Useless use of localtime in void context at - line 48.
293 Useless use of gmtime in void context at - line 49.
294 Useless use of getgrnam in void context at - line 50.
295 Useless use of getgrgid in void context at - line 51.
296 Useless use of getpwnam in void context at - line 52.
297 Useless use of getpwuid in void context at - line 53.
298 ########
299 # op.c
300 no warnings 'void' ; close STDIN ;
301 1 x 3 ;                 # OP_REPEAT
302                         # OP_GVSV
303 wantarray ;             # OP_WANTARRAY
304                         # OP_GV
305                         # OP_PADSV
306                         # OP_PADAV
307                         # OP_PADHV
308                         # OP_PADANY
309                         # OP_AV2ARYLEN
310 ref ;                   # OP_REF
311 \@a ;                   # OP_REFGEN
312 \$a ;                   # OP_SREFGEN
313 defined $a ;            # OP_DEFINED
314 hex $a ;                # OP_HEX
315 oct $a ;                # OP_OCT
316 length $a ;             # OP_LENGTH
317 substr $a,1 ;           # OP_SUBSTR
318 vec $a,1,2 ;            # OP_VEC
319 index $a,1,2 ;          # OP_INDEX
320 rindex $a,1,2 ;         # OP_RINDEX
321 sprintf $a ;            # OP_SPRINTF
322 $a[0] ;                 # OP_AELEM
323                         # OP_AELEMFAST
324 @a[0] ;                 # OP_ASLICE
325 #values %a ;            # OP_VALUES
326 #keys %a ;              # OP_KEYS
327 $a{0} ;                 # OP_HELEM
328 @a{0} ;                 # OP_HSLICE
329 unpack "a", "a" ;       # OP_UNPACK
330 pack $a,"" ;            # OP_PACK
331 join "" ;               # OP_JOIN
332 (@a)[0,1] ;             # OP_LSLICE
333                         # OP_ANONLIST
334                         # OP_ANONHASH
335 sort(1,2) ;             # OP_SORT
336 reverse(1,2) ;          # OP_REVERSE
337                         # OP_RANGE
338                         # OP_FLIP
339 (1 ..2) ;               # OP_FLOP
340 caller ;                # OP_CALLER
341 fileno STDIN ;          # OP_FILENO
342 eof STDIN ;             # OP_EOF
343 tell STDIN ;            # OP_TELL
344 readlink 1;             # OP_READLINK
345 time ;                  # OP_TIME
346 localtime ;             # OP_LOCALTIME
347 gmtime ;                # OP_GMTIME
348 eval { getgrnam 1 };    # OP_GGRNAM
349 eval { getgrgid 1 };    # OP_GGRGID
350 eval { getpwnam 1 };    # OP_GPWNAM
351 eval { getpwuid 1 };    # OP_GPWUID
352 EXPECT
353 ########
354 # op.c
355 use warnings 'void' ;
356 for (@{[0]}) { "$_" }           # check warning isn't duplicated
357 no warnings 'void' ;
358 for (@{[0]}) { "$_" }           # check warning isn't duplicated
359 EXPECT
360 Useless use of string in void context at - line 3.
361 ########
362 # op.c
363 use warnings 'void' ;
364 use Config ;
365 BEGIN {
366     if ( ! $Config{d_telldir}) {
367         print <<EOM ;
368 SKIPPED
369 # telldir not present
370 EOM
371         exit 
372     }
373 }
374 telldir 1 ;             # OP_TELLDIR
375 no warnings 'void' ;
376 telldir 1 ;             # OP_TELLDIR
377 EXPECT
378 Useless use of telldir in void context at - line 13.
379 ########
380 # op.c
381 use warnings 'void' ;
382 use Config ;
383 BEGIN {
384     if ( ! $Config{d_getppid}) {
385         print <<EOM ;
386 SKIPPED
387 # getppid not present
388 EOM
389         exit 
390     }
391 }
392 getppid ;               # OP_GETPPID
393 no warnings 'void' ;
394 getppid ;               # OP_GETPPID
395 EXPECT
396 Useless use of getppid in void context at - line 13.
397 ########
398 # op.c
399 use warnings 'void' ;
400 use Config ;
401 BEGIN {
402     if ( ! $Config{d_getpgrp}) {
403         print <<EOM ;
404 SKIPPED
405 # getpgrp not present
406 EOM
407         exit 
408     }
409 }
410 getpgrp ;               # OP_GETPGRP
411 no warnings 'void' ;
412 getpgrp ;               # OP_GETPGRP
413 EXPECT
414 Useless use of getpgrp in void context at - line 13.
415 ########
416 # op.c
417 use warnings 'void' ;
418 use Config ;
419 BEGIN {
420     if ( ! $Config{d_times}) {
421         print <<EOM ;
422 SKIPPED
423 # times not present
424 EOM
425         exit 
426     }
427 }
428 times ;                 # OP_TMS
429 no warnings 'void' ;
430 times ;                 # OP_TMS
431 EXPECT
432 Useless use of times in void context at - line 13.
433 ########
434 # op.c
435 use warnings 'void' ;
436 use Config ;
437 BEGIN {
438     if ( ! $Config{d_getprior} or $^O eq 'os2') { # Locks before fixpak22
439         print <<EOM ;
440 SKIPPED
441 # getpriority not present
442 EOM
443         exit 
444     }
445 }
446 getpriority 1,2;        # OP_GETPRIORITY
447 no warnings 'void' ;
448 getpriority 1,2;        # OP_GETPRIORITY
449 EXPECT
450 Useless use of getpriority in void context at - line 13.
451 ########
452 # op.c
453 use warnings 'void' ;
454 use Config ;
455 BEGIN {
456     if ( ! $Config{d_getlogin}) {
457         print <<EOM ;
458 SKIPPED
459 # getlogin not present
460 EOM
461         exit 
462     }
463 }
464 getlogin ;                      # OP_GETLOGIN
465 no warnings 'void' ;
466 getlogin ;                      # OP_GETLOGIN
467 EXPECT
468 Useless use of getlogin in void context at - line 13.
469 ########
470 # op.c
471 use warnings 'void' ;
472 use Config ; BEGIN {
473 if ( ! $Config{d_socket}) {
474     print <<EOM ;
475 SKIPPED
476 # getsockname not present
477 # getpeername not present
478 # gethostbyname not present
479 # gethostbyaddr not present
480 # gethostent not present
481 # getnetbyname not present
482 # getnetbyaddr not present
483 # getnetent not present
484 # getprotobyname not present
485 # getprotobynumber not present
486 # getprotoent not present
487 # getservbyname not present
488 # getservbyport not present
489 # getservent not present
490 EOM
491     exit 
492 } }
493 getsockname STDIN ;     # OP_GETSOCKNAME
494 getpeername STDIN ;     # OP_GETPEERNAME
495 gethostbyname 1 ;       # OP_GHBYNAME
496 gethostbyaddr 1,2;      # OP_GHBYADDR
497 gethostent ;            # OP_GHOSTENT
498 getnetbyname 1 ;        # OP_GNBYNAME
499 getnetbyaddr 1,2 ;      # OP_GNBYADDR
500 getnetent ;             # OP_GNETENT
501 getprotobyname 1;       # OP_GPBYNAME
502 getprotobynumber 1;     # OP_GPBYNUMBER
503 getprotoent ;           # OP_GPROTOENT
504 getservbyname 1,2;      # OP_GSBYNAME
505 getservbyport 1,2;      # OP_GSBYPORT
506 getservent ;            # OP_GSERVENT
507
508 no warnings 'void' ;
509 getsockname STDIN ;     # OP_GETSOCKNAME
510 getpeername STDIN ;     # OP_GETPEERNAME
511 gethostbyname 1 ;       # OP_GHBYNAME
512 gethostbyaddr 1,2;      # OP_GHBYADDR
513 gethostent ;            # OP_GHOSTENT
514 getnetbyname 1 ;        # OP_GNBYNAME
515 getnetbyaddr 1,2 ;      # OP_GNBYADDR
516 getnetent ;             # OP_GNETENT
517 getprotobyname 1;       # OP_GPBYNAME
518 getprotobynumber 1;     # OP_GPBYNUMBER
519 getprotoent ;           # OP_GPROTOENT
520 getservbyname 1,2;      # OP_GSBYNAME
521 getservbyport 1,2;      # OP_GSBYPORT
522 getservent ;            # OP_GSERVENT
523 INIT {
524    # some functions may not be there, so we exit without running
525    exit;
526 }
527 EXPECT
528 Useless use of getsockname in void context at - line 24.
529 Useless use of getpeername in void context at - line 25.
530 Useless use of gethostbyname in void context at - line 26.
531 Useless use of gethostbyaddr in void context at - line 27.
532 Useless use of gethostent in void context at - line 28.
533 Useless use of getnetbyname in void context at - line 29.
534 Useless use of getnetbyaddr in void context at - line 30.
535 Useless use of getnetent in void context at - line 31.
536 Useless use of getprotobyname in void context at - line 32.
537 Useless use of getprotobynumber in void context at - line 33.
538 Useless use of getprotoent in void context at - line 34.
539 Useless use of getservbyname in void context at - line 35.
540 Useless use of getservbyport in void context at - line 36.
541 Useless use of getservent in void context at - line 37.
542 ########
543 # op.c
544 use warnings 'void' ;
545 *a ; # OP_RV2GV
546 $a ; # OP_RV2SV
547 @a ; # OP_RV2AV
548 %a ; # OP_RV2HV
549 no warnings 'void' ;
550 *a ; # OP_RV2GV
551 $a ; # OP_RV2SV
552 @a ; # OP_RV2AV
553 %a ; # OP_RV2HV
554 EXPECT
555 Useless use of a variable in void context at - line 3.
556 Useless use of a variable in void context at - line 4.
557 Useless use of a variable in void context at - line 5.
558 Useless use of a variable in void context at - line 6.
559 ########
560 # op.c
561 use warnings 'void' ;
562 "abc"; # OP_CONST
563 7 ; # OP_CONST
564 no warnings 'void' ;
565 "abc"; # OP_CONST
566 7 ; # OP_CONST
567 EXPECT
568 Useless use of a constant in void context at - line 3.
569 Useless use of a constant in void context at - line 4.
570 ########
571 # op.c
572 BEGIN{ $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3; } # known scalar leak
573 use warnings 'misc' ;
574 my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
575 @a =~ /abc/ ;
576 @a =~ s/a/b/ ;
577 @a =~ tr/a/b/ ;
578 @$b =~ /abc/ ;
579 @$b =~ s/a/b/ ;
580 @$b =~ tr/a/b/ ;
581 %a =~ /abc/ ;
582 %a =~ s/a/b/ ;
583 %a =~ tr/a/b/ ;
584 %$c =~ /abc/ ;
585 %$c =~ s/a/b/ ;
586 %$c =~ tr/a/b/ ;
587 {
588 no warnings 'misc' ;
589 my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
590 @a =~ /abc/ ;
591 @a =~ s/a/b/ ;
592 @a =~ tr/a/b/ ;
593 @$b =~ /abc/ ;
594 @$b =~ s/a/b/ ;
595 @$b =~ tr/a/b/ ;
596 %a =~ /abc/ ;
597 %a =~ s/a/b/ ;
598 %a =~ tr/a/b/ ;
599 %$c =~ /abc/ ;
600 %$c =~ s/a/b/ ;
601 %$c =~ tr/a/b/ ;
602 }
603 EXPECT
604 Applying pattern match (m//) to @array will act on scalar(@array) at - line 5.
605 Applying substitution (s///) to @array will act on scalar(@array) at - line 6.
606 Can't modify private array in substitution (s///) at - line 6, near "s/a/b/ ;"
607 Applying transliteration (tr///) to @array will act on scalar(@array) at - line 7.
608 Applying pattern match (m//) to @array will act on scalar(@array) at - line 8.
609 Applying substitution (s///) to @array will act on scalar(@array) at - line 9.
610 Applying transliteration (tr///) to @array will act on scalar(@array) at - line 10.
611 Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 11.
612 Applying substitution (s///) to %hash will act on scalar(%hash) at - line 12.
613 Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 13.
614 Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 14.
615 Applying substitution (s///) to %hash will act on scalar(%hash) at - line 15.
616 Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 16.
617 BEGIN not safe after errors--compilation aborted at - line 18.
618 ########
619 # op.c
620 use warnings 'syntax' ;
621 my $a, $b = (1,2);
622 no warnings 'syntax' ;
623 my $c, $d = (1,2);
624 EXPECT
625 Parentheses missing around "my" list at - line 3.
626 ########
627 # op.c
628 use warnings 'syntax' ;
629 local $a, $b = (1,2);
630 no warnings 'syntax' ;
631 local $c, $d = (1,2);
632 EXPECT
633 Parentheses missing around "local" list at - line 3.
634 ########
635 # op.c
636 use warnings 'bareword' ;
637 print (ABC || 1) ;
638 no warnings 'bareword' ;
639 print (ABC || 1) ;
640 EXPECT
641 Bareword found in conditional at - line 3.
642 ########
643 --FILE-- abc
644
645 --FILE--
646 # op.c
647 use warnings 'misc' ;
648 open FH, "<abc" ;
649 $x = 1 if $x = <FH> ;
650 no warnings 'misc' ;
651 $x = 1 if $x = <FH> ;
652 EXPECT
653 Value of <HANDLE> construct can be "0"; test with defined() at - line 4.
654 ########
655 # op.c
656 use warnings 'misc' ;
657 opendir FH, "." ;
658 $x = 1 if $x = readdir FH ;
659 no warnings 'misc' ;
660 $x = 1 if $x = readdir FH ;
661 closedir FH ;
662 EXPECT
663 Value of readdir() operator can be "0"; test with defined() at - line 4.
664 ########
665 # op.c
666 use warnings 'misc' ;
667 $x = 1 if $x = <*> ;
668 no warnings 'misc' ;
669 $x = 1 if $x = <*> ;
670 EXPECT
671 Value of glob construct can be "0"; test with defined() at - line 3.
672 ########
673 # op.c
674 use warnings 'misc' ;
675 %a = (1,2,3,4) ;
676 $x = 1 if $x = each %a ;
677 no warnings 'misc' ;
678 $x = 1 if $x = each %a ;
679 EXPECT
680 Value of each() operator can be "0"; test with defined() at - line 4.
681 ########
682 # op.c
683 use warnings 'misc' ;
684 $x = 1 while $x = <*> and 0 ;
685 no warnings 'misc' ;
686 $x = 1 while $x = <*> and 0 ;
687 EXPECT
688 Value of glob construct can be "0"; test with defined() at - line 3.
689 ########
690 # op.c
691 use warnings 'misc' ;
692 opendir FH, "." ;
693 $x = 1 while $x = readdir FH and 0 ;
694 no warnings 'misc' ;
695 $x = 1 while $x = readdir FH and 0 ;
696 closedir FH ;
697 EXPECT
698 Value of readdir() operator can be "0"; test with defined() at - line 4.
699 ########
700 # op.c
701 use warnings 'redefine' ;
702 sub fred {}
703 sub fred {}
704 no warnings 'redefine' ;
705 sub fred {}
706 EXPECT
707 Subroutine fred redefined at - line 4.
708 ########
709 # op.c
710 use warnings 'redefine' ;
711 sub fred () { 1 }
712 sub fred () { 1 }
713 no warnings 'redefine' ;
714 sub fred () { 1 }
715 EXPECT
716 Constant subroutine fred redefined at - line 4.
717 ########
718 # op.c
719 use warnings 'redefine' ;
720 format FRED =
721 .
722 format FRED =
723 .
724 no warnings 'redefine' ;
725 format FRED =
726 .
727 EXPECT
728 Format FRED redefined at - line 5.
729 ########
730 # op.c
731 use warnings 'deprecated' ;
732 push FRED;
733 no warnings 'deprecated' ;
734 push FRED;
735 EXPECT
736 Array @FRED missing the @ in argument 1 of push() at - line 3.
737 ########
738 # op.c
739 use warnings 'deprecated' ;
740 @a = keys FRED ;
741 no warnings 'deprecated' ;
742 @a = keys FRED ;
743 EXPECT
744 Hash %FRED missing the % in argument 1 of keys() at - line 3.
745 ########
746 # op.c
747 use warnings 'syntax' ;
748 exec "$^X -e 1" ; 
749 my $a
750 EXPECT
751 Statement unlikely to be reached at - line 4.
752         (Maybe you meant system() when you said exec()?)
753 ########
754 # op.c
755 use warnings 'deprecated' ;
756 my @a; defined(@a);
757 EXPECT
758 defined(@array) is deprecated at - line 3.
759         (Maybe you should just omit the defined()?)
760 ########
761 # op.c
762 use warnings 'deprecated' ;
763 defined(@a = (1,2,3));
764 EXPECT
765 defined(@array) is deprecated at - line 3.
766         (Maybe you should just omit the defined()?)
767 ########
768 # op.c
769 use warnings 'deprecated' ;
770 my %h; defined(%h);
771 EXPECT
772 defined(%hash) is deprecated at - line 3.
773         (Maybe you should just omit the defined()?)
774 ########
775 # op.c
776 no warnings 'syntax' ;
777 exec "$^X -e 1" ; 
778 my $a
779 EXPECT
780
781 ########
782 # op.c
783 sub fred();
784 sub fred($) {}
785 EXPECT
786 Prototype mismatch: sub main::fred () vs ($) at - line 3.
787 ########
788 # op.c
789 $^W = 0 ;
790 sub fred() ;
791 sub fred($) {}
792 {
793     no warnings 'prototype' ;
794     sub Fred() ;
795     sub Fred($) {}
796     use warnings 'prototype' ;
797     sub freD() ;
798     sub freD($) {}
799 }
800 sub FRED() ;
801 sub FRED($) {}
802 EXPECT
803 Prototype mismatch: sub main::fred () vs ($) at - line 4.
804 Prototype mismatch: sub main::freD () vs ($) at - line 11.
805 Prototype mismatch: sub main::FRED () vs ($) at - line 14.
806 ########
807 # op.c
808 use warnings 'syntax' ;
809 join /---/, 'x', 'y', 'z';
810 EXPECT
811 /---/ should probably be written as "---" at - line 3.
812 ########
813 # op.c [Perl_peep]
814 use warnings 'prototype' ;
815 fred() ; 
816 sub fred ($$) {}
817 no warnings 'prototype' ;
818 joe() ; 
819 sub joe ($$) {}
820 EXPECT
821 main::fred() called too early to check prototype at - line 3.
822 ########
823 # op.c [Perl_newATTRSUB]
824 --FILE-- abc.pm
825 use warnings 'void' ;
826 BEGIN { $| = 1; print "in begin\n"; }
827 CHECK { print "in check\n"; }
828 INIT { print "in init\n"; }
829 END { print "in end\n"; }
830 print "in mainline\n";
831 1;
832 --FILE--
833 use abc;
834 delete $INC{"abc.pm"};
835 require abc;
836 do "abc.pm";
837 EXPECT
838 in begin
839 in mainline
840 in check
841 in init
842 in begin
843 Too late to run CHECK block at abc.pm line 3.
844 Too late to run INIT block at abc.pm line 4.
845 in mainline
846 in begin
847 Too late to run CHECK block at abc.pm line 3.
848 Too late to run INIT block at abc.pm line 4.
849 in mainline
850 in end
851 in end
852 in end
853 ########
854 # op.c [Perl_newATTRSUB]
855 --FILE-- abc.pm
856 no warnings 'void' ;
857 BEGIN { $| = 1; print "in begin\n"; }
858 CHECK { print "in check\n"; }
859 INIT { print "in init\n"; }
860 END { print "in end\n"; }
861 print "in mainline\n";
862 1;
863 --FILE--
864 require abc;
865 do "abc.pm";
866 EXPECT
867 in begin
868 in mainline
869 in begin
870 in mainline
871 in end
872 in end