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