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