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