This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Warn by default for constant my sub redefinition
[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
599cee73
PM
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
RGS
13 Useless use of sort in scalar context
14 my $x = sort (2,1,3);
15
599cee73
PM
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
PM
33 my $a, $b = (1,2);
34
df5b6949 35 Parentheses missing around "local" list at -e line 1.
599cee73
PM
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
PM
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
PM
65 exec "true" ; my $a
66
f10b0346 67 defined(@array) is deprecated
cc507455 68 (Maybe you should just omit the defined()?)
69794302
MJD
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 ;
89474f50 75
271c8bde
FC
76 "my %s" used in sort comparison
77
89474f50 78 $[ used in comparison (did you mean $] ?)
e508c8a4
MH
79
80 length() used on @array (did you mean "scalar(@array)"?)
81 length() used on %hash (did you mean "scalar(keys %hash)"?)
82
eb6e2d6f
GS
83 /---/ should probably be written as "---"
84 join(/---/, @foo);
599cee73 85
767a6a26
PM
86 %s() called too early to check prototype [Perl_peep]
87 fred() ; sub fred ($$) {}
88
89
15a8c21e 90 Package '%s' not found (did you use the incorrect case?)
3b434eb1 91
f34840d8
MJD
92 Use of /g modifier is meaningless in split
93
276b2a0c
RGS
94 Possible precedence problem on bitwise %c operator [Perl_ck_bitop]
95
0453d815
PM
96 Mandatory Warnings
97 ------------------
98 Prototype mismatch: [cv_ckproto]
99 sub fred() ;
100 sub fred($) {}
101
0453d815
PM
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 ;
2b7cddde
NC
1091 if $a
110 = 1 ;
4438c4b7 111no warnings 'syntax' ;
0453d815 1121 if $a = 1 ;
2b7cddde
NC
1131 if $a
114 = 1 ;
599cee73
PM
115EXPECT
116Found = in conditional, should be == at - line 3.
2b7cddde 117Found = in conditional, should be == at - line 4.
599cee73
PM
118########
119# op.c
6b7c6d95
FC
120use warnings 'syntax' ;
121use constant foo => 1;
1221 if $a = foo ;
123no warnings 'syntax' ;
1241 if $a = foo ;
125EXPECT
126########
127# op.c
a1063b2d
RH
128my (@foo, %foo);
129%main::foo->{"bar"};
130%foo->{"bar"};
131@main::foo->[23];
132@foo->[23];
133$main::foo = {}; %$main::foo->{"bar"};
134$foo = {}; %$foo->{"bar"};
135$main::foo = []; @$main::foo->[34];
136$foo = []; @$foo->[34];
137no warnings 'deprecated';
138%main::foo->{"bar"};
139%foo->{"bar"};
140@main::foo->[23];
141@foo->[23];
142$main::foo = {}; %$main::foo->{"bar"};
143$foo = {}; %$foo->{"bar"};
144$main::foo = []; @$main::foo->[34];
145$foo = []; @$foo->[34];
146EXPECT
d1d15184 147Using a hash as a reference is deprecated at - line 3.
a1063b2d 148Using a hash as a reference is deprecated at - line 4.
d1d15184 149Using an array as a reference is deprecated at - line 5.
a1063b2d 150Using an array as a reference is deprecated at - line 6.
d1d15184 151Using a hash as a reference is deprecated at - line 7.
a1063b2d 152Using a hash as a reference is deprecated at - line 8.
d1d15184 153Using an array as a reference is deprecated at - line 9.
a1063b2d 154Using an array as a reference is deprecated at - line 10.
a1063b2d
RH
155########
156# op.c
4438c4b7 157use warnings 'void' ; close STDIN ;
baed7faa
FC
158#line 2
1591 x 3 ; # OP_REPEAT (folded)
160(1) x 3 ; # OP_REPEAT
599cee73
PM
161 # OP_GVSV
162wantarray ; # OP_WANTARRAY
163 # OP_GV
164 # OP_PADSV
165 # OP_PADAV
166 # OP_PADHV
167 # OP_PADANY
168 # OP_AV2ARYLEN
169ref ; # OP_REF
170\@a ; # OP_REFGEN
171\$a ; # OP_SREFGEN
172defined $a ; # OP_DEFINED
173hex $a ; # OP_HEX
174oct $a ; # OP_OCT
175length $a ; # OP_LENGTH
176substr $a,1 ; # OP_SUBSTR
177vec $a,1,2 ; # OP_VEC
178index $a,1,2 ; # OP_INDEX
179rindex $a,1,2 ; # OP_RINDEX
180sprintf $a ; # OP_SPRINTF
181$a[0] ; # OP_AELEM
182 # OP_AELEMFAST
183@a[0] ; # OP_ASLICE
184#values %a ; # OP_VALUES
185#keys %a ; # OP_KEYS
186$a{0} ; # OP_HELEM
187@a{0} ; # OP_HSLICE
188unpack "a", "a" ; # OP_UNPACK
189pack $a,"" ; # OP_PACK
190join "" ; # OP_JOIN
191(@a)[0,1] ; # OP_LSLICE
192 # OP_ANONLIST
193 # OP_ANONHASH
194sort(1,2) ; # OP_SORT
195reverse(1,2) ; # OP_REVERSE
196 # OP_RANGE
197 # OP_FLIP
198(1 ..2) ; # OP_FLOP
199caller ; # OP_CALLER
200fileno STDIN ; # OP_FILENO
201eof STDIN ; # OP_EOF
202tell STDIN ; # OP_TELL
203readlink 1; # OP_READLINK
204time ; # OP_TIME
205localtime ; # OP_LOCALTIME
206gmtime ; # OP_GMTIME
dfe13c55
GS
207eval { getgrnam 1 }; # OP_GGRNAM
208eval { getgrgid 1 }; # OP_GGRGID
209eval { getpwnam 1 }; # OP_GPWNAM
210eval { getpwuid 1 }; # OP_GPWUID
78e1b766 211prototype "foo"; # OP_PROTOTYPE
74295f0b
MS
212$a ~~ $b; # OP_SMARTMATCH
213$a <=> $b; # OP_NCMP
703227f5
FC
214use 5.015;
215__SUB__ # OP_RUNCV
599cee73 216EXPECT
baed7faa 217Useless use of a constant ("111") in void context at - line 2.
42d38218 218Useless use of repeat (x) in void context at - line 3.
599cee73
PM
219Useless use of wantarray in void context at - line 5.
220Useless use of reference-type operator in void context at - line 12.
221Useless use of reference constructor in void context at - line 13.
d6c467eb 222Useless use of single ref constructor in void context at - line 14.
599cee73
PM
223Useless use of defined operator in void context at - line 15.
224Useless use of hex in void context at - line 16.
225Useless use of oct in void context at - line 17.
226Useless use of length in void context at - line 18.
227Useless use of substr in void context at - line 19.
228Useless use of vec in void context at - line 20.
229Useless use of index in void context at - line 21.
230Useless use of rindex in void context at - line 22.
231Useless use of sprintf in void context at - line 23.
232Useless use of array element in void context at - line 24.
233Useless use of array slice in void context at - line 26.
f1612b5c 234Useless use of hash element in void context at - line 29.
599cee73
PM
235Useless use of hash slice in void context at - line 30.
236Useless use of unpack in void context at - line 31.
237Useless use of pack in void context at - line 32.
297b36dc 238Useless use of join or string in void context at - line 33.
599cee73
PM
239Useless use of list slice in void context at - line 34.
240Useless use of sort in void context at - line 37.
241Useless use of reverse in void context at - line 38.
242Useless use of range (or flop) in void context at - line 41.
243Useless use of caller in void context at - line 42.
244Useless use of fileno in void context at - line 43.
245Useless use of eof in void context at - line 44.
246Useless use of tell in void context at - line 45.
247Useless use of readlink in void context at - line 46.
248Useless use of time in void context at - line 47.
249Useless use of localtime in void context at - line 48.
250Useless use of gmtime in void context at - line 49.
251Useless use of getgrnam in void context at - line 50.
252Useless use of getgrgid in void context at - line 51.
253Useless use of getpwnam in void context at - line 52.
254Useless use of getpwuid in void context at - line 53.
78e1b766 255Useless use of subroutine prototype in void context at - line 54.
f5df4782
RGS
256Useless use of smart match in void context at - line 55.
257Useless use of numeric comparison (<=>) in void context at - line 56.
703227f5 258Useless use of __SUB__ in void context at - line 58.
599cee73
PM
259########
260# op.c
a801c63c
RGS
261use warnings 'void' ; close STDIN ;
262my $x = sort (2,1,3);
263no warnings 'void' ;
264$x = sort (2,1,3);
265EXPECT
266Useless use of sort in scalar context at - line 3.
267########
268# op.c
4438c4b7 269no warnings 'void' ; close STDIN ;
0453d815
PM
2701 x 3 ; # OP_REPEAT
271 # OP_GVSV
272wantarray ; # OP_WANTARRAY
273 # OP_GV
274 # OP_PADSV
275 # OP_PADAV
276 # OP_PADHV
277 # OP_PADANY
278 # OP_AV2ARYLEN
279ref ; # OP_REF
280\@a ; # OP_REFGEN
281\$a ; # OP_SREFGEN
282defined $a ; # OP_DEFINED
283hex $a ; # OP_HEX
284oct $a ; # OP_OCT
285length $a ; # OP_LENGTH
286substr $a,1 ; # OP_SUBSTR
287vec $a,1,2 ; # OP_VEC
288index $a,1,2 ; # OP_INDEX
289rindex $a,1,2 ; # OP_RINDEX
290sprintf $a ; # OP_SPRINTF
291$a[0] ; # OP_AELEM
292 # OP_AELEMFAST
293@a[0] ; # OP_ASLICE
294#values %a ; # OP_VALUES
295#keys %a ; # OP_KEYS
296$a{0} ; # OP_HELEM
297@a{0} ; # OP_HSLICE
298unpack "a", "a" ; # OP_UNPACK
299pack $a,"" ; # OP_PACK
300join "" ; # OP_JOIN
301(@a)[0,1] ; # OP_LSLICE
302 # OP_ANONLIST
303 # OP_ANONHASH
304sort(1,2) ; # OP_SORT
305reverse(1,2) ; # OP_REVERSE
306 # OP_RANGE
307 # OP_FLIP
308(1 ..2) ; # OP_FLOP
309caller ; # OP_CALLER
310fileno STDIN ; # OP_FILENO
311eof STDIN ; # OP_EOF
312tell STDIN ; # OP_TELL
313readlink 1; # OP_READLINK
314time ; # OP_TIME
315localtime ; # OP_LOCALTIME
316gmtime ; # OP_GMTIME
317eval { getgrnam 1 }; # OP_GGRNAM
318eval { getgrgid 1 }; # OP_GGRGID
319eval { getpwnam 1 }; # OP_GPWNAM
320eval { getpwuid 1 }; # OP_GPWUID
78e1b766 321prototype "foo"; # OP_PROTOTYPE
0453d815
PM
322EXPECT
323########
324# op.c
4438c4b7 325use warnings 'void' ;
68c73484 326for (@{[0]}) { "$_" } # check warning isn't duplicated
4438c4b7 327no warnings 'void' ;
0453d815 328for (@{[0]}) { "$_" } # check warning isn't duplicated
68c73484
JH
329EXPECT
330Useless use of string in void context at - line 3.
331########
332# op.c
4438c4b7 333use warnings 'void' ;
599cee73
PM
334use Config ;
335BEGIN {
336 if ( ! $Config{d_telldir}) {
337 print <<EOM ;
338SKIPPED
339# telldir not present
340EOM
341 exit
342 }
343}
344telldir 1 ; # OP_TELLDIR
4438c4b7 345no warnings 'void' ;
0453d815 346telldir 1 ; # OP_TELLDIR
599cee73
PM
347EXPECT
348Useless use of telldir in void context at - line 13.
349########
350# op.c
4438c4b7 351use warnings 'void' ;
599cee73
PM
352use Config ;
353BEGIN {
354 if ( ! $Config{d_getppid}) {
355 print <<EOM ;
356SKIPPED
357# getppid not present
358EOM
359 exit
360 }
361}
362getppid ; # OP_GETPPID
4438c4b7 363no warnings 'void' ;
0453d815 364getppid ; # OP_GETPPID
599cee73
PM
365EXPECT
366Useless use of getppid in void context at - line 13.
367########
368# op.c
4438c4b7 369use warnings 'void' ;
599cee73
PM
370use Config ;
371BEGIN {
372 if ( ! $Config{d_getpgrp}) {
373 print <<EOM ;
374SKIPPED
375# getpgrp not present
376EOM
377 exit
378 }
379}
380getpgrp ; # OP_GETPGRP
4438c4b7 381no warnings 'void' ;
0453d815 382getpgrp ; # OP_GETPGRP
599cee73
PM
383EXPECT
384Useless use of getpgrp in void context at - line 13.
385########
386# op.c
4438c4b7 387use warnings 'void' ;
599cee73
PM
388use Config ;
389BEGIN {
390 if ( ! $Config{d_times}) {
391 print <<EOM ;
392SKIPPED
393# times not present
394EOM
395 exit
396 }
397}
398times ; # OP_TMS
4438c4b7 399no warnings 'void' ;
0453d815 400times ; # OP_TMS
599cee73
PM
401EXPECT
402Useless use of times in void context at - line 13.
403########
404# op.c
4438c4b7 405use warnings 'void' ;
599cee73
PM
406use Config ;
407BEGIN {
e96326af 408 if ( ! $Config{d_getprior} or $^O eq 'os2') { # Locks before fixpak22
599cee73
PM
409 print <<EOM ;
410SKIPPED
411# getpriority not present
412EOM
413 exit
414 }
415}
416getpriority 1,2; # OP_GETPRIORITY
4438c4b7 417no warnings 'void' ;
0453d815 418getpriority 1,2; # OP_GETPRIORITY
599cee73
PM
419EXPECT
420Useless use of getpriority in void context at - line 13.
421########
422# op.c
4438c4b7 423use warnings 'void' ;
599cee73
PM
424use Config ;
425BEGIN {
426 if ( ! $Config{d_getlogin}) {
427 print <<EOM ;
428SKIPPED
429# getlogin not present
430EOM
431 exit
432 }
433}
434getlogin ; # OP_GETLOGIN
4438c4b7 435no warnings 'void' ;
0453d815 436getlogin ; # OP_GETLOGIN
599cee73
PM
437EXPECT
438Useless use of getlogin in void context at - line 13.
439########
440# op.c
4438c4b7 441use warnings 'void' ;
599cee73
PM
442use Config ; BEGIN {
443if ( ! $Config{d_socket}) {
444 print <<EOM ;
445SKIPPED
446# getsockname not present
447# getpeername not present
448# gethostbyname not present
449# gethostbyaddr not present
450# gethostent not present
451# getnetbyname not present
452# getnetbyaddr not present
453# getnetent not present
454# getprotobyname not present
455# getprotobynumber not present
456# getprotoent not present
457# getservbyname not present
458# getservbyport not present
459# getservent not present
460EOM
461 exit
462} }
463getsockname STDIN ; # OP_GETSOCKNAME
464getpeername STDIN ; # OP_GETPEERNAME
465gethostbyname 1 ; # OP_GHBYNAME
466gethostbyaddr 1,2; # OP_GHBYADDR
467gethostent ; # OP_GHOSTENT
468getnetbyname 1 ; # OP_GNBYNAME
469getnetbyaddr 1,2 ; # OP_GNBYADDR
470getnetent ; # OP_GNETENT
471getprotobyname 1; # OP_GPBYNAME
472getprotobynumber 1; # OP_GPBYNUMBER
473getprotoent ; # OP_GPROTOENT
474getservbyname 1,2; # OP_GSBYNAME
475getservbyport 1,2; # OP_GSBYPORT
476getservent ; # OP_GSERVENT
0453d815 477
4438c4b7 478no warnings 'void' ;
0453d815
PM
479getsockname STDIN ; # OP_GETSOCKNAME
480getpeername STDIN ; # OP_GETPEERNAME
481gethostbyname 1 ; # OP_GHBYNAME
482gethostbyaddr 1,2; # OP_GHBYADDR
483gethostent ; # OP_GHOSTENT
484getnetbyname 1 ; # OP_GNBYNAME
485getnetbyaddr 1,2 ; # OP_GNBYADDR
486getnetent ; # OP_GNETENT
487getprotobyname 1; # OP_GPBYNAME
488getprotobynumber 1; # OP_GPBYNUMBER
489getprotoent ; # OP_GPROTOENT
490getservbyname 1,2; # OP_GSBYNAME
491getservbyport 1,2; # OP_GSBYPORT
492getservent ; # OP_GSERVENT
dfe13c55
GS
493INIT {
494 # some functions may not be there, so we exit without running
495 exit;
496}
599cee73
PM
497EXPECT
498Useless use of getsockname in void context at - line 24.
499Useless use of getpeername in void context at - line 25.
500Useless use of gethostbyname in void context at - line 26.
501Useless use of gethostbyaddr in void context at - line 27.
502Useless use of gethostent in void context at - line 28.
503Useless use of getnetbyname in void context at - line 29.
504Useless use of getnetbyaddr in void context at - line 30.
505Useless use of getnetent in void context at - line 31.
506Useless use of getprotobyname in void context at - line 32.
507Useless use of getprotobynumber in void context at - line 33.
508Useless use of getprotoent in void context at - line 34.
509Useless use of getservbyname in void context at - line 35.
510Useless use of getservbyport in void context at - line 36.
511Useless use of getservent in void context at - line 37.
512########
513# op.c
4438c4b7 514use warnings 'void' ;
599cee73
PM
515*a ; # OP_RV2GV
516$a ; # OP_RV2SV
517@a ; # OP_RV2AV
518%a ; # OP_RV2HV
4438c4b7 519no warnings 'void' ;
0453d815
PM
520*a ; # OP_RV2GV
521$a ; # OP_RV2SV
522@a ; # OP_RV2AV
523%a ; # OP_RV2HV
599cee73
PM
524EXPECT
525Useless use of a variable in void context at - line 3.
526Useless use of a variable in void context at - line 4.
527Useless use of a variable in void context at - line 5.
528Useless use of a variable in void context at - line 6.
529########
530# op.c
4438c4b7 531use warnings 'void' ;
599cee73
PM
532"abc"; # OP_CONST
5337 ; # OP_CONST
86f9315f
RD
534"x" . "y"; # optimized to OP_CONST
5352 + 2; # optimized to OP_CONST
e7fec78e 536use constant U => undef;
fa01e093 537U;
919f76a3 538qq/" \n/;
fa01e093 5395 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT
e7fec78e 540print "boo\n" if U; # test OPpCONST_SHORTCIRCUIT
4438c4b7 541no warnings 'void' ;
0453d815
PM
542"abc"; # OP_CONST
5437 ; # OP_CONST
86f9315f
RD
544"x" . "y"; # optimized to OP_CONST
5452 + 2; # optimized to OP_CONST
599cee73 546EXPECT
919f76a3 547Useless use of a constant ("abc") in void context at - line 3.
86f9315f 548Useless use of a constant (7) in void context at - line 4.
919f76a3 549Useless use of a constant ("xy") in void context at - line 5.
86f9315f 550Useless use of a constant (4) in void context at - line 6.
fa01e093 551Useless use of a constant (undef) in void context at - line 8.
919f76a3 552Useless use of a constant ("\"\t\n") in void context at - line 9.
599cee73
PM
553########
554# op.c
34ee6772
BF
555use utf8;
556use open qw( :utf8 :std );
557use warnings 'void' ;
558"àḆc"; # OP_CONST
559"Ẋ" . "ƴ"; # optimized to OP_CONST
560FOO; # Bareword optimized to OP_CONST
561use constant ů => undef;
562ů;
5635 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT
564print "boo\n" if ů; # test OPpCONST_SHORTCIRCUIT
565no warnings 'void' ;
566"àḆc"; # OP_CONST
567"Ẋ" . "ƴ"; # optimized to OP_CONST
568EXPECT
919f76a3
RGS
569Useless use of a constant ("\340\x{1e06}c") in void context at - line 5.
570Useless use of a constant ("\x{1e8a}\x{1b4}") in void context at - line 6.
571Useless use of a constant ("\x{ff26}\x{ff2f}\x{ff2f}") in void context at - line 7.
34ee6772
BF
572Useless use of a constant (undef) in void context at - line 9.
573########
574# op.c
7f01dc7a 575#
e476b1b5 576use warnings 'misc' ;
b08e453b 577my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;my $d = 'test';
599cee73 578@a =~ /abc/ ;
c6771ab6
FC
579@a2 =~ s/a/b/ ;
580@a3 =~ tr/a/b/ ;
599cee73
PM
581@$b =~ /abc/ ;
582@$b =~ s/a/b/ ;
583@$b =~ tr/a/b/ ;
584%a =~ /abc/ ;
c6771ab6
FC
585%a2 =~ s/a/b/ ;
586%a3 =~ tr/a/b/ ;
599cee73
PM
587%$c =~ /abc/ ;
588%$c =~ s/a/b/ ;
589%$c =~ tr/a/b/ ;
b08e453b 590$d =~ tr/a/b/d ;
c6771ab6 591$d2 =~ tr/a/bc/;
0453d815 592{
e476b1b5 593no warnings 'misc' ;
b08e453b 594my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; my $d = 'test';
0453d815
PM
595@a =~ /abc/ ;
596@a =~ s/a/b/ ;
597@a =~ tr/a/b/ ;
598@$b =~ /abc/ ;
599@$b =~ s/a/b/ ;
600@$b =~ tr/a/b/ ;
601%a =~ /abc/ ;
602%a =~ s/a/b/ ;
603%a =~ tr/a/b/ ;
604%$c =~ /abc/ ;
605%$c =~ s/a/b/ ;
606%$c =~ tr/a/b/ ;
b08e453b 607$d =~ tr/a/b/d ;
608$d =~ tr/a/bc/ ;
0453d815 609}
599cee73 610EXPECT
c6771ab6
FC
611Applying pattern match (m//) to @a will act on scalar(@a) at - line 5.
612Applying substitution (s///) to @a2 will act on scalar(@a2) at - line 6.
613Applying transliteration (tr///) to @a3 will act on scalar(@a3) at - line 7.
42d38218
MS
614Applying pattern match (m//) to @array will act on scalar(@array) at - line 8.
615Applying substitution (s///) to @array will act on scalar(@array) at - line 9.
f1612b5c 616Applying transliteration (tr///) to @array will act on scalar(@array) at - line 10.
c6771ab6
FC
617Applying pattern match (m//) to %a will act on scalar(%a) at - line 11.
618Applying substitution (s///) to %a2 will act on scalar(%a2) at - line 12.
619Applying transliteration (tr///) to %a3 will act on scalar(%a3) at - line 13.
42d38218
MS
620Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 14.
621Applying substitution (s///) to %hash will act on scalar(%hash) at - line 15.
f1612b5c 622Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 16.
b08e453b 623Useless use of /d modifier in transliteration operator at - line 17.
624Replacement list is longer than search list at - line 18.
c6771ab6 625Can't modify array dereference in substitution (s///) at - line 6, near "s/a/b/ ;"
b08e453b 626BEGIN not safe after errors--compilation aborted at - line 20.
599cee73
PM
627########
628# op.c
8473848f 629use warnings 'parenthesis' ;
599cee73 630my $a, $b = (1,2);
8473848f 631my @foo,%bar, $quux; # there's a TAB here
bac662ee 632my $x, $y or print;
8473848f 633no warnings 'parenthesis' ;
0453d815 634my $c, $d = (1,2);
599cee73 635EXPECT
df5b6949 636Parentheses missing around "my" list at - line 3.
8473848f 637Parentheses missing around "my" list at - line 4.
599cee73
PM
638########
639# op.c
8473848f
RGS
640use warnings 'parenthesis' ;
641our $a, $b = (1,2);
642no warnings 'parenthesis' ;
643our $c, $d = (1,2);
644EXPECT
645Parentheses missing around "our" list at - line 3.
646########
647# op.c
648use warnings 'parenthesis' ;
599cee73 649local $a, $b = (1,2);
8473848f
RGS
650local *f, *g;
651no warnings 'parenthesis' ;
0453d815 652local $c, $d = (1,2);
599cee73 653EXPECT
df5b6949 654Parentheses missing around "local" list at - line 3.
8473848f 655Parentheses missing around "local" list at - line 4.
599cee73
PM
656########
657# op.c
e476b1b5 658use warnings 'bareword' ;
599cee73 659print (ABC || 1) ;
e476b1b5 660no warnings 'bareword' ;
0453d815 661print (ABC || 1) ;
599cee73 662EXPECT
34d09196 663Bareword found in conditional at - line 3.
599cee73
PM
664########
665--FILE-- abc
666
667--FILE--
668# op.c
e476b1b5 669use warnings 'misc' ;
599cee73
PM
670open FH, "<abc" ;
671$x = 1 if $x = <FH> ;
502e5101
NC
672$x = 1 if $x
673 = <FH> ;
e476b1b5 674no warnings 'misc' ;
0453d815 675$x = 1 if $x = <FH> ;
502e5101
NC
676$x = 1 if $x
677 = <FH> ;
599cee73
PM
678EXPECT
679Value of <HANDLE> construct can be "0"; test with defined() at - line 4.
502e5101 680Value of <HANDLE> construct can be "0"; test with defined() at - line 5.
599cee73
PM
681########
682# op.c
e476b1b5 683use warnings 'misc' ;
599cee73
PM
684opendir FH, "." ;
685$x = 1 if $x = readdir FH ;
502e5101
NC
686$x = 1 if $x
687 = readdir FH ;
e476b1b5 688no warnings 'misc' ;
0453d815 689$x = 1 if $x = readdir FH ;
502e5101
NC
690$x = 1 if $x
691 = readdir FH ;
599cee73
PM
692closedir FH ;
693EXPECT
694Value of readdir() operator can be "0"; test with defined() at - line 4.
502e5101 695Value of readdir() operator can be "0"; test with defined() at - line 5.
599cee73
PM
696########
697# op.c
e476b1b5 698use warnings 'misc' ;
599cee73 699$x = 1 if $x = <*> ;
502e5101
NC
700$x = 1 if $x
701 = <*> ;
e476b1b5 702no warnings 'misc' ;
0453d815 703$x = 1 if $x = <*> ;
502e5101
NC
704$x = 1 if $x
705 = <*> ;
599cee73
PM
706EXPECT
707Value of glob construct can be "0"; test with defined() at - line 3.
502e5101 708Value of glob construct can be "0"; test with defined() at - line 4.
599cee73
PM
709########
710# op.c
e476b1b5 711use warnings 'misc' ;
599cee73
PM
712%a = (1,2,3,4) ;
713$x = 1 if $x = each %a ;
e476b1b5 714no warnings 'misc' ;
0453d815 715$x = 1 if $x = each %a ;
599cee73
PM
716EXPECT
717Value of each() operator can be "0"; test with defined() at - line 4.
718########
719# op.c
e476b1b5 720use warnings 'misc' ;
599cee73 721$x = 1 while $x = <*> and 0 ;
e476b1b5 722no warnings 'misc' ;
0453d815 723$x = 1 while $x = <*> and 0 ;
599cee73
PM
724EXPECT
725Value of glob construct can be "0"; test with defined() at - line 3.
726########
727# op.c
e476b1b5 728use warnings 'misc' ;
599cee73
PM
729opendir FH, "." ;
730$x = 1 while $x = readdir FH and 0 ;
e476b1b5 731no warnings 'misc' ;
0453d815 732$x = 1 while $x = readdir FH and 0 ;
599cee73
PM
733closedir FH ;
734EXPECT
735Value of readdir() operator can be "0"; test with defined() at - line 4.
736########
737# op.c
59e10468
RGS
738use warnings 'misc';
739open FH, "<abc";
59e10468
RGS
740($_ = <FH>) // ($_ = 1);
741opendir DH, ".";
59e10468 742%a = (1,2,3,4) ;
59e10468
RGS
743EXPECT
744########
745# op.c
4438c4b7 746use warnings 'redefine' ;
599cee73
PM
747sub fred {}
748sub fred {}
2d4e1700
NC
749sub fred { # warning should be for this line
750}
4438c4b7 751no warnings 'redefine' ;
0453d815 752sub fred {}
2d4e1700
NC
753sub fred {
754}
599cee73
PM
755EXPECT
756Subroutine fred redefined at - line 4.
2d4e1700 757Subroutine fred redefined at - line 5.
599cee73
PM
758########
759# op.c
4438c4b7 760use warnings 'redefine' ;
599cee73
PM
761sub fred () { 1 }
762sub fred () { 1 }
4438c4b7 763no warnings 'redefine' ;
0453d815 764sub fred () { 1 }
599cee73
PM
765EXPECT
766Constant subroutine fred redefined at - line 4.
767########
768# op.c
efcf35c4
FC
769sub fred () { 1 }
770sub fred () { 2 }
771EXPECT
772Constant subroutine fred redefined at - line 3.
773########
774# op.c
775sub fred () { 1 }
776*fred = sub () { 2 };
777EXPECT
778Constant subroutine main::fred redefined at - line 3.
779########
780# op.c
ee0832ce
FC
781use feature "lexical_subs", "state";
782my sub fred () { 1 }
783sub fred { 2 };
784my sub george { 1 }
785sub george () { 2 } # should *not* produce redef warnings by default
786state sub phred () { 1 }
787sub phred { 2 };
788state sub jorge { 1 }
789sub jorge () { 2 } # should *not* produce redef warnings by default
790EXPECT
791The lexical_subs feature is experimental at - line 2.
792Prototype mismatch: sub fred () vs none at - line 4.
793Constant subroutine fred redefined at - line 4.
794Prototype mismatch: sub george: none vs () at - line 6.
795Prototype mismatch: sub phred () vs none at - line 8.
796Constant subroutine phred redefined at - line 8.
797Prototype mismatch: sub jorge: none vs () at - line 10.
798########
799# op.c
036b4402
GS
800no warnings 'redefine' ;
801sub fred () { 1 }
802sub fred () { 2 }
803EXPECT
036b4402
GS
804########
805# op.c
806no warnings 'redefine' ;
807sub fred () { 1 }
808*fred = sub () { 2 };
809EXPECT
036b4402
GS
810########
811# op.c
4438c4b7 812use warnings 'redefine' ;
599cee73
PM
813format FRED =
814.
815format FRED =
816.
4438c4b7 817no warnings 'redefine' ;
0453d815
PM
818format FRED =
819.
599cee73
PM
820EXPECT
821Format FRED redefined at - line 5.
822########
823# op.c
599cee73 824push FRED;
e476b1b5 825no warnings 'deprecated' ;
0453d815 826push FRED;
599cee73 827EXPECT
d1d15184 828Array @FRED missing the @ in argument 1 of push() at - line 2.
599cee73
PM
829########
830# op.c
599cee73 831@a = keys FRED ;
e476b1b5 832no warnings 'deprecated' ;
0453d815 833@a = keys FRED ;
599cee73 834EXPECT
d1d15184 835Hash %FRED missing the % in argument 1 of keys() at - line 2.
599cee73
PM
836########
837# op.c
4438c4b7 838use warnings 'syntax' ;
dfe13c55 839exec "$^X -e 1" ;
599cee73
PM
840my $a
841EXPECT
7b903762 842Statement unlikely to be reached at - line 4.
cc507455 843 (Maybe you meant system() when you said exec()?)
69794302 844########
ea31ed66
GG
845# op.c, no warning if exec isn't a statement.
846use warnings 'syntax' ;
847$a || exec "$^X -e 1" ;
848my $a
849EXPECT
850########
69794302 851# op.c
b880f709
NC
852defined(@a);
853EXPECT
854defined(@array) is deprecated at - line 2.
855 (Maybe you should just omit the defined()?)
856########
857# op.c
69794302
MJD
858my @a; defined(@a);
859EXPECT
d1d15184 860defined(@array) is deprecated at - line 2.
cc507455 861 (Maybe you should just omit the defined()?)
69794302
MJD
862########
863# op.c
69794302
MJD
864defined(@a = (1,2,3));
865EXPECT
d1d15184 866defined(@array) is deprecated at - line 2.
cc507455 867 (Maybe you should just omit the defined()?)
69794302
MJD
868########
869# op.c
b880f709
NC
870defined(%h);
871EXPECT
872defined(%hash) is deprecated at - line 2.
873 (Maybe you should just omit the defined()?)
874########
875# op.c
69794302
MJD
876my %h; defined(%h);
877EXPECT
d1d15184 878defined(%hash) is deprecated at - line 2.
cc507455 879 (Maybe you should just omit the defined()?)
0453d815
PM
880########
881# op.c
4438c4b7 882no warnings 'syntax' ;
0453d815
PM
883exec "$^X -e 1" ;
884my $a
885EXPECT
886
887########
888# op.c
889sub fred();
890sub fred($) {}
105ff74c
FC
891use constant foo=>bar; sub foo(@);
892use constant bav=>bar; sub bav(); # no warning
893sub btu; sub btu();
0453d815
PM
894EXPECT
895Prototype mismatch: sub main::fred () vs ($) at - line 3.
105ff74c
FC
896Prototype mismatch: sub foo () vs (@) at - line 4.
897Prototype mismatch: sub btu: none vs () at - line 6.
0453d815
PM
898########
899# op.c
dab1c735
BF
900use utf8;
901use open qw( :utf8 :std );
902sub frèd();
903sub frèd($) {}
904EXPECT
905Prototype mismatch: sub main::frèd () vs ($) at - line 5.
906########
907# op.c
908use utf8;
909use open qw( :utf8 :std );
910use warnings;
911eval "sub fòò (\$\0) {}";
912EXPECT
97eb901d 913Illegal character in prototype for main::fòò : $\0 at (eval 1) line 1.
dab1c735
BF
914########
915# op.c
916use utf8;
917use open qw( :utf8 :std );
918use warnings;
919eval "sub foo (\0) {}";
920EXPECT
97eb901d 921Illegal character in prototype for main::foo : \0 at (eval 1) line 1.
dab1c735
BF
922########
923# op.c
924use utf8;
925use open qw( :utf8 :std );
926use warnings;
927BEGIN { $::{"foo"} = "\$\0L\351on" }
928BEGIN { eval "sub foo (\$\0L\x{c3}\x{a9}on) {}"; }
929EXPECT
930Illegal character in prototype for main::foo : $\x{0}L... at (eval 1) line 1.
931########
932# op.c
933use utf8;
934use open qw( :utf8 :std );
935use warnings;
936BEGIN { eval "sub foo (\0) {}"; }
937EXPECT
97eb901d
BF
938Illegal character in prototype for main::foo : \0 at (eval 1) line 1.
939########
940# op.c
941use warnings;
942eval "sub foo (\xAB) {}";
943EXPECT
944Illegal character in prototype for main::foo : \x{ab} at (eval 1) line 1.
945########
946# op.c
947use utf8;
948use open qw( :utf8 :std );
949use warnings;
950BEGIN { eval "sub foo (\x{30cb}) {}"; }
951EXPECT
952Illegal character in prototype for main::foo : \x{30cb} at (eval 1) line 1.
dab1c735
BF
953########
954# op.c
955use utf8;
956use open qw( :utf8 :std );
957use warnings;
958BEGIN { $::{"foo"} = "\x{30cb}" }
959BEGIN { eval "sub foo {}"; }
960EXPECT
961Prototype mismatch: sub main::foo (ニ) vs none at (eval 1) line 1.
962########
963# op.c
0453d815
PM
964$^W = 0 ;
965sub fred() ;
966sub fred($) {}
967{
e476b1b5 968 no warnings 'prototype' ;
0453d815
PM
969 sub Fred() ;
970 sub Fred($) {}
e476b1b5 971 use warnings 'prototype' ;
0453d815
PM
972 sub freD() ;
973 sub freD($) {}
974}
975sub FRED() ;
976sub FRED($) {}
977EXPECT
978Prototype mismatch: sub main::fred () vs ($) at - line 4.
979Prototype mismatch: sub main::freD () vs ($) at - line 11.
980Prototype mismatch: sub main::FRED () vs ($) at - line 14.
eb6e2d6f 981########
271c8bde
FC
982# op.c [S_simplify_sort]
983# [perl #86136]
984my @tests = split /^/, '
985 sort {$a <=> $b} @a;
986 sort {$a cmp $b} @a;
987 { use integer; sort {$a <=> $b} @a}
988 sort {$b <=> $a} @a;
989 sort {$b cmp $a} @a;
990 { use integer; sort {$b <=> $a} @a}
991';
992for my $pragma ('use warnings "syntax";', '') {
993 for my $vars ('', 'my $a;', 'my $b;', 'my ($a,$b);') {
994 for my $inner_stmt ('', 'print;', 'func();') {
995 eval "#line " . ++$line . "01 -\n$pragma\n$vars"
996 . join "", map s/sort \{\K/$inner_stmt/r, @tests;
997 $@ and die;
998 }
999 }
1000}
1001sub func{}
1002use warnings 'syntax';
1003my $a;
1004# These used to be errors!
1005sort { ; } $a <=> $b;
1006sort { ; } $a, "<=>";
1007sort { ; } $a, $cmp;
1008sort $a, $b if $cmpany_name;
1009sort if $a + $cmp;
1010sort @t; $a + $cmp;
1011EXPECT
1012"my $a" used in sort comparison at - line 403.
1013"my $a" used in sort comparison at - line 404.
1014"my $a" used in sort comparison at - line 405.
1015"my $a" used in sort comparison at - line 406.
1016"my $a" used in sort comparison at - line 407.
1017"my $a" used in sort comparison at - line 408.
1018"my $a" used in sort comparison at - line 503.
1019"my $a" used in sort comparison at - line 504.
1020"my $a" used in sort comparison at - line 505.
1021"my $a" used in sort comparison at - line 506.
1022"my $a" used in sort comparison at - line 507.
1023"my $a" used in sort comparison at - line 508.
1024"my $a" used in sort comparison at - line 603.
1025"my $a" used in sort comparison at - line 604.
1026"my $a" used in sort comparison at - line 605.
1027"my $a" used in sort comparison at - line 606.
1028"my $a" used in sort comparison at - line 607.
1029"my $a" used in sort comparison at - line 608.
1030"my $b" used in sort comparison at - line 703.
1031"my $b" used in sort comparison at - line 704.
1032"my $b" used in sort comparison at - line 705.
1033"my $b" used in sort comparison at - line 706.
1034"my $b" used in sort comparison at - line 707.
1035"my $b" used in sort comparison at - line 708.
1036"my $b" used in sort comparison at - line 803.
1037"my $b" used in sort comparison at - line 804.
1038"my $b" used in sort comparison at - line 805.
1039"my $b" used in sort comparison at - line 806.
1040"my $b" used in sort comparison at - line 807.
1041"my $b" used in sort comparison at - line 808.
1042"my $b" used in sort comparison at - line 903.
1043"my $b" used in sort comparison at - line 904.
1044"my $b" used in sort comparison at - line 905.
1045"my $b" used in sort comparison at - line 906.
1046"my $b" used in sort comparison at - line 907.
1047"my $b" used in sort comparison at - line 908.
1048"my $a" used in sort comparison at - line 1003.
1049"my $b" used in sort comparison at - line 1003.
1050"my $a" used in sort comparison at - line 1004.
1051"my $b" used in sort comparison at - line 1004.
1052"my $a" used in sort comparison at - line 1005.
1053"my $b" used in sort comparison at - line 1005.
1054"my $b" used in sort comparison at - line 1006.
1055"my $a" used in sort comparison at - line 1006.
1056"my $b" used in sort comparison at - line 1007.
1057"my $a" used in sort comparison at - line 1007.
1058"my $b" used in sort comparison at - line 1008.
1059"my $a" used in sort comparison at - line 1008.
1060"my $a" used in sort comparison at - line 1103.
1061"my $b" used in sort comparison at - line 1103.
1062"my $a" used in sort comparison at - line 1104.
1063"my $b" used in sort comparison at - line 1104.
1064"my $a" used in sort comparison at - line 1105.
1065"my $b" used in sort comparison at - line 1105.
1066"my $b" used in sort comparison at - line 1106.
1067"my $a" used in sort comparison at - line 1106.
1068"my $b" used in sort comparison at - line 1107.
1069"my $a" used in sort comparison at - line 1107.
1070"my $b" used in sort comparison at - line 1108.
1071"my $a" used in sort comparison at - line 1108.
1072"my $a" used in sort comparison at - line 1203.
1073"my $b" used in sort comparison at - line 1203.
1074"my $a" used in sort comparison at - line 1204.
1075"my $b" used in sort comparison at - line 1204.
1076"my $a" used in sort comparison at - line 1205.
1077"my $b" used in sort comparison at - line 1205.
1078"my $b" used in sort comparison at - line 1206.
1079"my $a" used in sort comparison at - line 1206.
1080"my $b" used in sort comparison at - line 1207.
1081"my $a" used in sort comparison at - line 1207.
1082"my $b" used in sort comparison at - line 1208.
1083"my $a" used in sort comparison at - line 1208.
1084########
a2e39214
FC
1085# op.c [S_simplify_sort]
1086use warnings 'syntax'; use 5.01;
1087state $a;
1088sort { $a <=> $b } ();
1089EXPECT
1090"state $a" used in sort comparison at - line 4.
1091########
89474f50
FC
1092# op.c [Perl_ck_cmp]
1093use warnings 'syntax' ;
1094no warnings 'deprecated';
1095@a = $[ < 5;
1096@a = $[ > 5;
1097@a = $[ <= 5;
1098@a = $[ >= 5;
1099@a = 42 < $[;
1100@a = 42 > $[;
1101@a = 42 <= $[;
1102@a = 42 >= $[;
1103use integer;
1104@a = $[ < 5;
1105@a = $[ > 5;
1106@a = $[ <= 5;
1107@a = $[ >= 5;
1108@a = 42 < $[;
1109@a = 42 > $[;
1110@a = 42 <= $[;
1111@a = 42 >= $[;
7c2b3c78
FC
1112no integer;
1113@a = $[ < $5;
1114@a = $[ > $5;
1115@a = $[ <= $5;
1116@a = $[ >= $5;
1117@a = $42 < $[;
1118@a = $42 > $[;
1119@a = $42 <= $[;
1120@a = $42 >= $[;
1121use integer;
1122@a = $[ < $5;
1123@a = $[ > $5;
1124@a = $[ <= $5;
1125@a = $[ >= $5;
1126@a = $42 < $[;
1127@a = $42 > $[;
1128@a = $42 <= $[;
1129@a = $42 >= $[;
89474f50
FC
1130EXPECT
1131$[ used in numeric lt (<) (did you mean $] ?) at - line 4.
1132$[ used in numeric gt (>) (did you mean $] ?) at - line 5.
1133$[ used in numeric le (<=) (did you mean $] ?) at - line 6.
1134$[ used in numeric ge (>=) (did you mean $] ?) at - line 7.
1135$[ used in numeric lt (<) (did you mean $] ?) at - line 8.
1136$[ used in numeric gt (>) (did you mean $] ?) at - line 9.
1137$[ used in numeric le (<=) (did you mean $] ?) at - line 10.
1138$[ used in numeric ge (>=) (did you mean $] ?) at - line 11.
1139$[ used in numeric lt (<) (did you mean $] ?) at - line 13.
1140$[ used in numeric gt (>) (did you mean $] ?) at - line 14.
1141$[ used in numeric le (<=) (did you mean $] ?) at - line 15.
1142$[ used in numeric ge (>=) (did you mean $] ?) at - line 16.
1143$[ used in numeric lt (<) (did you mean $] ?) at - line 17.
1144$[ used in numeric gt (>) (did you mean $] ?) at - line 18.
1145$[ used in numeric le (<=) (did you mean $] ?) at - line 19.
1146$[ used in numeric ge (>=) (did you mean $] ?) at - line 20.
1147########
e508c8a4
MH
1148# op.c [Perl_ck_length]
1149use warnings 'syntax' ;
1150length(@a);
579333ee
FC
1151length(%b);
1152length(@$c);
1153length(%$d);
e508c8a4 1154length($a);
9710ad41 1155length(my %h);
579333ee 1156length(my @g);
e508c8a4 1157EXPECT
579333ee
FC
1158length() used on @a (did you mean "scalar(@a)"?) at - line 3.
1159length() used on %b (did you mean "scalar(keys %b)"?) at - line 4.
e508c8a4
MH
1160length() used on @array (did you mean "scalar(@array)"?) at - line 5.
1161length() used on %hash (did you mean "scalar(keys %hash)"?) at - line 6.
579333ee
FC
1162length() used on %h (did you mean "scalar(keys %h)"?) at - line 8.
1163length() used on @g (did you mean "scalar(@g)"?) at - line 9.
e508c8a4 1164########
eb6e2d6f
GS
1165# op.c
1166use warnings 'syntax' ;
1167join /---/, 'x', 'y', 'z';
1168EXPECT
1169/---/ should probably be written as "---" at - line 3.
767a6a26 1170########
ce16c625
BF
1171# op.c
1172use utf8;
1173use open qw( :utf8 :std );
1174use warnings 'syntax' ;
1175join /~~~/, 'x', 'y', 'z';
1176EXPECT
1177/~~~/ should probably be written as "~~~" at - line 5.
1178########
767a6a26 1179# op.c [Perl_peep]
e476b1b5 1180use warnings 'prototype' ;
767a6a26
PM
1181fred() ;
1182sub fred ($$) {}
e476b1b5 1183no warnings 'prototype' ;
767a6a26
PM
1184joe() ;
1185sub joe ($$) {}
1186EXPECT
1187main::fred() called too early to check prototype at - line 3.
ddda08b7
GS
1188########
1189# op.c [Perl_newATTRSUB]
1190--FILE-- abc.pm
1191use warnings 'void' ;
1192BEGIN { $| = 1; print "in begin\n"; }
1193CHECK { print "in check\n"; }
1194INIT { print "in init\n"; }
1195END { print "in end\n"; }
1196print "in mainline\n";
11971;
1198--FILE--
1199use abc;
1200delete $INC{"abc.pm"};
1201require abc;
1202do "abc.pm";
1203EXPECT
1204in begin
1205in mainline
1206in check
1207in init
1208in begin
1209Too late to run CHECK block at abc.pm line 3.
1210Too late to run INIT block at abc.pm line 4.
1211in mainline
1212in begin
1213Too late to run CHECK block at abc.pm line 3.
1214Too late to run INIT block at abc.pm line 4.
1215in mainline
1216in end
1217in end
1218in end
1219########
1220# op.c [Perl_newATTRSUB]
1221--FILE-- abc.pm
1222no warnings 'void' ;
1223BEGIN { $| = 1; print "in begin\n"; }
1224CHECK { print "in check\n"; }
1225INIT { print "in init\n"; }
1226END { print "in end\n"; }
1227print "in mainline\n";
12281;
1229--FILE--
1230require abc;
1231do "abc.pm";
1232EXPECT
1233in begin
1234in mainline
1235in begin
1236in mainline
1237in end
1238in end
936edb8b
RH
1239########
1240# op.c
1241my @x;
f87c3213 1242use warnings 'syntax' ;
936edb8b
RH
1243push(@x);
1244unshift(@x);
f87c3213 1245no warnings 'syntax' ;
936edb8b
RH
1246push(@x);
1247unshift(@x);
1248EXPECT
de4864e4
JH
1249Useless use of push with no values at - line 4.
1250Useless use of unshift with no values at - line 5.
a27978d3
AMS
1251########
1252# op.c
f34840d8
MJD
1253# 20020401 mjd@plover.com at suggestion of jfriedl@yahoo.com
1254use warnings 'regexp';
1255split /blah/g, "blah";
1256no warnings 'regexp';
1257split /blah/g, "blah";
1258EXPECT
1259Use of /g modifier is meaningless in split at - line 4.
276b2a0c
RGS
1260########
1261# op.c
1262use warnings 'precedence';
1263$a = $b & $c == $d;
1264$a = $b ^ $c != $d;
1265$a = $b | $c > $d;
1266$a = $b < $c & $d;
1267$a = $b >= $c ^ $d;
1268$a = $b <= $c | $d;
1269$a = $b <=> $c & $d;
2b84528b 1270$a &= $b == $c; $a |= $b == $c; $a ^= $b == $c; # shouldn't warn
276b2a0c
RGS
1271no warnings 'precedence';
1272$a = $b & $c == $d;
1273$a = $b ^ $c != $d;
1274$a = $b | $c > $d;
1275$a = $b < $c & $d;
1276$a = $b >= $c ^ $d;
1277$a = $b <= $c | $d;
1278$a = $b <=> $c & $d;
1279EXPECT
1280Possible precedence problem on bitwise & operator at - line 3.
1281Possible precedence problem on bitwise ^ operator at - line 4.
1282Possible precedence problem on bitwise | operator at - line 5.
1283Possible precedence problem on bitwise & operator at - line 6.
1284Possible precedence problem on bitwise ^ operator at - line 7.
1285Possible precedence problem on bitwise | operator at - line 8.
1286Possible precedence problem on bitwise & operator at - line 9.
1287########
1288# op.c
1289use integer;
1290use warnings 'precedence';
1291$a = $b & $c == $d;
1292$a = $b ^ $c != $d;
1293$a = $b | $c > $d;
1294$a = $b < $c & $d;
1295$a = $b >= $c ^ $d;
1296$a = $b <= $c | $d;
1297$a = $b <=> $c & $d;
1298no warnings 'precedence';
1299$a = $b & $c == $d;
1300$a = $b ^ $c != $d;
1301$a = $b | $c > $d;
1302$a = $b < $c & $d;
1303$a = $b >= $c ^ $d;
1304$a = $b <= $c | $d;
1305$a = $b <=> $c & $d;
1306EXPECT
1307Possible precedence problem on bitwise & operator at - line 4.
1308Possible precedence problem on bitwise ^ operator at - line 5.
1309Possible precedence problem on bitwise | operator at - line 6.
1310Possible precedence problem on bitwise & operator at - line 7.
1311Possible precedence problem on bitwise ^ operator at - line 8.
1312Possible precedence problem on bitwise | operator at - line 9.
1313Possible precedence problem on bitwise & operator at - line 10.
ddeae0f1
DM
1314########
1315# op.c
1316
1317# ok => local() has desired effect;
1318# ignore=> local() silently ignored
1319
1320use warnings 'syntax';
1321
1322local(undef); # OP_UNDEF ignore
1323sub lval : lvalue {};
1324local(lval()); # OP_ENTERSUB
1325local($x **= 1); # OP_POW
1326local($x *= 1); # OP_MULTIPLY
1327local($x /= 1); # OP_DIVIDE
1328local($x %= 1); # OP_MODULO
1329local($x x= 1); # OP_REPEAT
1330local($x += 1); # OP_ADD
1331local($x -= 1); # OP_SUBTRACT
1332local($x .= 1); # OP_CONCAT
1333local($x <<= 1); # OP_LEFT_SHIFT
1334local($x >>= 1); # OP_RIGHT_SHIFT
1335local($x &= 1); # OP_BIT_AND
1336local($x ^= 1); # OP_BIT_XOR
1337local($x |= 1); # OP_BIT_OR
1338{
1339 use integer;
1340 local($x *= 1); # OP_I_MULTIPLY
1341 local($x /= 1); # OP_I_DIVIDE
1342 local($x %= 1); # OP_I_MODULO
1343 local($x += 1); # OP_I_ADD
1344 local($x -= 1); # OP_I_SUBTRACT
1345}
1346local($x?$y:$z) = 1; # OP_COND_EXPR ok
1347# these two are fatal run-time errors instead
1348#local(@$a); # OP_RV2AV ok
1349#local(%$a); # OP_RV2HV ok
1350local(*a); # OP_RV2GV ok
1351local(@a[1,2]); # OP_ASLICE ok
1352local(@a{1,2}); # OP_HSLICE ok
1353local(@a = (1,2)); # OP_AASSIGN
1354local($$x); # OP_RV2SV ok
1355local($#a); # OP_AV2ARYLEN
1356local($x = 1); # OP_SASSIGN
1357local($x &&= 1); # OP_ANDASSIGN
1358local($x ||= 1); # OP_ORASSIGN
1359local($x //= 1); # OP_DORASSIGN
1360local($a[0]); # OP_AELEMFAST ok
1361
1362local(substr($x,0,1)); # OP_SUBSTR
1363local(pos($x)); # OP_POS
1364local(vec($x,0,1)); # OP_VEC
1365local($a[$b]); # OP_AELEM ok
1366local($a{$b}); # OP_HELEM ok
1367
1368no warnings 'syntax';
1369EXPECT
1370Useless localization of subroutine entry at - line 10.
1371Useless localization of exponentiation (**) at - line 11.
1372Useless localization of multiplication (*) at - line 12.
1373Useless localization of division (/) at - line 13.
1374Useless localization of modulus (%) at - line 14.
1375Useless localization of repeat (x) at - line 15.
1376Useless localization of addition (+) at - line 16.
1377Useless localization of subtraction (-) at - line 17.
1378Useless localization of concatenation (.) or string at - line 18.
1379Useless localization of left bitshift (<<) at - line 19.
1380Useless localization of right bitshift (>>) at - line 20.
1381Useless localization of bitwise and (&) at - line 21.
1382Useless localization of bitwise xor (^) at - line 22.
1383Useless localization of bitwise or (|) at - line 23.
1384Useless localization of integer multiplication (*) at - line 26.
1385Useless localization of integer division (/) at - line 27.
1386Useless localization of integer modulus (%) at - line 28.
1387Useless localization of integer addition (+) at - line 29.
1388Useless localization of integer subtraction (-) at - line 30.
1389Useless localization of list assignment at - line 39.
1390Useless localization of array length at - line 41.
1391Useless localization of scalar assignment at - line 42.
1392Useless localization of logical and assignment (&&=) at - line 43.
1393Useless localization of logical or assignment (||=) at - line 44.
1394Useless localization of defined or assignment (//=) at - line 45.
1395Useless localization of substr at - line 48.
1396Useless localization of match position at - line 49.
1397Useless localization of vec at - line 50.
7921d0f2
DM
1398########
1399# op.c
7921d0f2
DM
1400my $x1 if 0;
1401my @x2 if 0;
1402my %x3 if 0;
1403my ($x4) if 0;
1404my ($x5,@x6, %x7) if 0;
14050 && my $z1;
14060 && my (%z2);
1407# these shouldn't warn
1408our $x if 0;
1409our $x unless 0;
1410if (0) { my $w1 }
1411if (my $w2) { $a=1 }
1412if ($a && (my $w3 = 1)) {$a = 2}
1413
1414EXPECT
d1d15184 1415Deprecated use of my() in false conditional at - line 2.
7921d0f2
DM
1416Deprecated use of my() in false conditional at - line 3.
1417Deprecated use of my() in false conditional at - line 4.
1418Deprecated use of my() in false conditional at - line 5.
1419Deprecated use of my() in false conditional at - line 6.
1420Deprecated use of my() in false conditional at - line 7.
1421Deprecated use of my() in false conditional at - line 8.
55b67815
RGS
1422########
1423# op.c
36b2db7e
FC
1424$[ = 1;
1425($[) = 1;
1426use warnings 'deprecated';
1427$[ = 2;
1428($[) = 2;
1429no warnings 'deprecated';
1430$[ = 3;
1431($[) = 3;
1432EXPECT
1433Use of assignment to $[ is deprecated at - line 2.
1434Use of assignment to $[ is deprecated at - line 3.
1435Use of assignment to $[ is deprecated at - line 5.
1436Use of assignment to $[ is deprecated at - line 6.
1437########
1438# op.c
75068674
RGS
1439use warnings 'void';
1440@x = split /y/, "z";
1441$x = split /y/, "z";
1442 split /y/, "z";
1443no warnings 'void';
1444@x = split /y/, "z";
1445$x = split /y/, "z";
1446 split /y/, "z";
1447EXPECT
1448Useless use of split in void context at - line 5.
34ee6772
BF
1449########
1450# op.c
1451use warnings 'redefine' ;
1452use utf8;
1453use open qw( :utf8 :std );
1454sub frèd {}
1455sub frèd {}
1456no warnings 'redefine' ;
1457sub frèd {}
1458EXPECT
1459Subroutine frèd redefined at - line 6.
1460########
1461# op.c
1462use warnings 'redefine' ;
1463use utf8;
1464use open qw( :utf8 :std );
1465sub frèd () { 1 }
1466sub frèd () { 1 }
1467no warnings 'redefine' ;
1468sub frèd () { 1 }
1469EXPECT
1470Constant subroutine frèd redefined at - line 6.
1471########
1472# op.c
34ee6772
BF
1473use utf8;
1474use open qw( :utf8 :std );
1475sub frèd () { 1 }
1476sub frèd () { 2 }
1477EXPECT
efcf35c4 1478Constant subroutine frèd redefined at - line 5.
34ee6772
BF
1479########
1480# op.c
34ee6772
BF
1481use utf8;
1482use open qw( :utf8 :std );
1483sub frèd () { 1 }
1484*frèd = sub () { 2 };
1485EXPECT
efcf35c4 1486Constant subroutine main::frèd redefined at - line 5.
34ee6772
BF
1487########
1488# op.c
1489use warnings 'redefine' ;
1490use utf8;
1491use open qw( :utf8 :std );
1492sub ᚠርƊ {}
1493sub ᚠርƊ {}
1494no warnings 'redefine' ;
1495sub ᚠርƊ {}
1496EXPECT
1497Subroutine ᚠርƊ redefined at - line 6.
1498########
1499# op.c
1500use warnings 'redefine' ;
1501use utf8;
1502use open qw( :utf8 :std );
1503sub ᚠርƊ () { 1 }
1504sub ᚠርƊ () { 1 }
1505no warnings 'redefine' ;
1506sub ᚠርƊ () { 1 }
1507EXPECT
1508Constant subroutine ᚠርƊ redefined at - line 6.
1509########
1510# op.c
34ee6772
BF
1511use utf8;
1512use open qw( :utf8 :std );
1513sub ᚠርƊ () { 1 }
1514sub ᚠርƊ () { 2 }
1515EXPECT
efcf35c4 1516Constant subroutine ᚠርƊ redefined at - line 5.
34ee6772
BF
1517########
1518# op.c
34ee6772
BF
1519use utf8;
1520use open qw( :utf8 :std );
1521sub ᚠርƊ () { 1 }
1522*ᚠርƊ = sub () { 2 };
1523EXPECT
efcf35c4 1524Constant subroutine main::ᚠርƊ redefined at - line 5.
34ee6772 1525########
d787f4a5
NC
1526# OPTION regex
1527sub DynaLoader::dl_error {};
1528use warnings;
1529# We're testing that the warnings report the same line number:
1530eval <<'EOC' or die $@;
1531{
1532 DynaLoader::boot_DynaLoader("DynaLoader");
1533}
1534EOC
1535eval <<'EOC' or die $@;
1536BEGIN {
1537 DynaLoader::boot_DynaLoader("DynaLoader");
1538}
15391
1540EOC
1541EXPECT
1542OPTION regex
1543\ASubroutine DynaLoader::dl_error redefined at \(eval 1\) line 2\.
b5ab070a 1544?(?s).*
d787f4a5
NC
1545Subroutine DynaLoader::dl_error redefined at \(eval 2\) line 2\.
1546########