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