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