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