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