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