fix coredump with MULTIPLICITY (ckWARN() needs early curcop init)
[p5sagit/p5-mst-13.2.git] / t / pragma / warn-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
39 Applying %s to %s will act on scalar(%s)
40 my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
41 @a =~ /abc/ ;
42 @a =~ s/a/b/ ;
43 @a =~ tr/a/b/ ;
44 @$b =~ /abc/ ;
45 @$b =~ s/a/b/ ;
46 @$b =~ tr/a/b/ ;
47 %a =~ /abc/ ;
48 %a =~ s/a/b/ ;
49 %a =~ tr/a/b/ ;
50 %$c =~ /abc/ ;
51 %$c =~ s/a/b/ ;
52 %$c =~ tr/a/b/ ;
53
54
55 Parens missing around "my" list at -e line 1.
56 my $a, $b = (1,2);
57
58 Parens missing around "local" list at -e line 1.
59 local $a, $b = (1,2);
60
61 Probable precedence problem on logical or at -e line 1.
62 use warning 'syntax'; my $x = print(ABC || 1);
63
64 Value of %s may be \"0\"; use \"defined\"
65 $x = 1 if $x = <FH> ;
66 $x = 1 while $x = <FH> ;
67
68 Subroutine fred redefined at -e line 1.
69 sub fred{1;} sub fred{1;}
70
71 Constant subroutine %s redefined
72 sub fred() {1;} sub fred() {1;}
73
74 Format FRED redefined at /tmp/x line 5.
75 format FRED =
76 .
77 format FRED =
78 .
79
80 Array @%s missing the @ in argument %d of %s()
81 push fred ;
82
83 Hash %%%s missing the %% in argument %d of %s()
84 keys joe ;
85
86 Statement unlikely to be reached
87 (Maybe you meant system() when you said exec()?
88 exec "true" ; my $a
89
90
91__END__
92# op.c
93use warning 'unsafe' ;
94my $x ;
95my $x ;
96EXPECT
97"my" variable $x masks earlier declaration in same scope at - line 4.
98########
99# op.c
100use warning 'unsafe' ;
101sub x {
102 my $x;
103 sub y {
104 $x
105 }
106 }
107EXPECT
108Variable "$x" will not stay shared at - line 7.
109########
110# op.c
111use warning 'unsafe' ;
112sub x {
113 my $x;
114 sub y {
115 sub { $x }
116 }
117 }
118EXPECT
119Variable "$x" may be unavailable at - line 6.
120########
121# op.c
122use warning 'syntax' ;
1231 if $a = 1 ;
124EXPECT
125Found = in conditional, should be == at - line 3.
126########
127# op.c
128use warning 'deprecated' ;
129split ;
130EXPECT
131Use of implicit split to @_ is deprecated at - line 3.
132########
133# op.c
134use warning 'deprecated' ;
135$a = split ;
136EXPECT
137Use of implicit split to @_ is deprecated at - line 3.
138########
139# op.c
140use warning 'void' ; close STDIN ;
1411 x 3 ; # OP_REPEAT
142 # OP_GVSV
143wantarray ; # OP_WANTARRAY
144 # OP_GV
145 # OP_PADSV
146 # OP_PADAV
147 # OP_PADHV
148 # OP_PADANY
149 # OP_AV2ARYLEN
150ref ; # OP_REF
151\@a ; # OP_REFGEN
152\$a ; # OP_SREFGEN
153defined $a ; # OP_DEFINED
154hex $a ; # OP_HEX
155oct $a ; # OP_OCT
156length $a ; # OP_LENGTH
157substr $a,1 ; # OP_SUBSTR
158vec $a,1,2 ; # OP_VEC
159index $a,1,2 ; # OP_INDEX
160rindex $a,1,2 ; # OP_RINDEX
161sprintf $a ; # OP_SPRINTF
162$a[0] ; # OP_AELEM
163 # OP_AELEMFAST
164@a[0] ; # OP_ASLICE
165#values %a ; # OP_VALUES
166#keys %a ; # OP_KEYS
167$a{0} ; # OP_HELEM
168@a{0} ; # OP_HSLICE
169unpack "a", "a" ; # OP_UNPACK
170pack $a,"" ; # OP_PACK
171join "" ; # OP_JOIN
172(@a)[0,1] ; # OP_LSLICE
173 # OP_ANONLIST
174 # OP_ANONHASH
175sort(1,2) ; # OP_SORT
176reverse(1,2) ; # OP_REVERSE
177 # OP_RANGE
178 # OP_FLIP
179(1 ..2) ; # OP_FLOP
180caller ; # OP_CALLER
181fileno STDIN ; # OP_FILENO
182eof STDIN ; # OP_EOF
183tell STDIN ; # OP_TELL
184readlink 1; # OP_READLINK
185time ; # OP_TIME
186localtime ; # OP_LOCALTIME
187gmtime ; # OP_GMTIME
188getgrnam 1; # OP_GGRNAM
189getgrgid 1 ; # OP_GGRGID
190getpwnam 1; # OP_GPWNAM
191getpwuid 1; # OP_GPWUID
192EXPECT
193Useless use of repeat in void context at - line 3.
194Useless use of wantarray in void context at - line 5.
195Useless use of reference-type operator in void context at - line 12.
196Useless use of reference constructor in void context at - line 13.
197Useless use of scalar ref constructor in void context at - line 14.
198Useless use of defined operator in void context at - line 15.
199Useless use of hex in void context at - line 16.
200Useless use of oct in void context at - line 17.
201Useless use of length in void context at - line 18.
202Useless use of substr in void context at - line 19.
203Useless use of vec in void context at - line 20.
204Useless use of index in void context at - line 21.
205Useless use of rindex in void context at - line 22.
206Useless use of sprintf in void context at - line 23.
207Useless use of array element in void context at - line 24.
208Useless use of array slice in void context at - line 26.
209Useless use of hash elem in void context at - line 29.
210Useless use of hash slice in void context at - line 30.
211Useless use of unpack in void context at - line 31.
212Useless use of pack in void context at - line 32.
213Useless use of join in void context at - line 33.
214Useless use of list slice in void context at - line 34.
215Useless use of sort in void context at - line 37.
216Useless use of reverse in void context at - line 38.
217Useless use of range (or flop) in void context at - line 41.
218Useless use of caller in void context at - line 42.
219Useless use of fileno in void context at - line 43.
220Useless use of eof in void context at - line 44.
221Useless use of tell in void context at - line 45.
222Useless use of readlink in void context at - line 46.
223Useless use of time in void context at - line 47.
224Useless use of localtime in void context at - line 48.
225Useless use of gmtime in void context at - line 49.
226Useless use of getgrnam in void context at - line 50.
227Useless use of getgrgid in void context at - line 51.
228Useless use of getpwnam in void context at - line 52.
229Useless use of getpwuid in void context at - line 53.
230########
231# op.c
232use warning 'void' ;
233use Config ;
234BEGIN {
235 if ( ! $Config{d_telldir}) {
236 print <<EOM ;
237SKIPPED
238# telldir not present
239EOM
240 exit
241 }
242}
243telldir 1 ; # OP_TELLDIR
244EXPECT
245Useless use of telldir in void context at - line 13.
246########
247# op.c
248use warning 'void' ;
249use Config ;
250BEGIN {
251 if ( ! $Config{d_getppid}) {
252 print <<EOM ;
253SKIPPED
254# getppid not present
255EOM
256 exit
257 }
258}
259getppid ; # OP_GETPPID
260EXPECT
261Useless use of getppid in void context at - line 13.
262########
263# op.c
264use warning 'void' ;
265use Config ;
266BEGIN {
267 if ( ! $Config{d_getpgrp}) {
268 print <<EOM ;
269SKIPPED
270# getpgrp not present
271EOM
272 exit
273 }
274}
275getpgrp ; # OP_GETPGRP
276EXPECT
277Useless use of getpgrp in void context at - line 13.
278########
279# op.c
280use warning 'void' ;
281use Config ;
282BEGIN {
283 if ( ! $Config{d_times}) {
284 print <<EOM ;
285SKIPPED
286# times not present
287EOM
288 exit
289 }
290}
291times ; # OP_TMS
292EXPECT
293Useless use of times in void context at - line 13.
294########
295# op.c
296use warning 'void' ;
297use Config ;
298BEGIN {
299 if ( ! $Config{d_getprior}) {
300 print <<EOM ;
301SKIPPED
302# getpriority not present
303EOM
304 exit
305 }
306}
307getpriority 1,2; # OP_GETPRIORITY
308EXPECT
309Useless use of getpriority in void context at - line 13.
310########
311# op.c
312use warning 'void' ;
313use Config ;
314BEGIN {
315 if ( ! $Config{d_getlogin}) {
316 print <<EOM ;
317SKIPPED
318# getlogin not present
319EOM
320 exit
321 }
322}
323getlogin ; # OP_GETLOGIN
324EXPECT
325Useless use of getlogin in void context at - line 13.
326########
327# op.c
328use warning 'void' ;
329use Config ; BEGIN {
330if ( ! $Config{d_socket}) {
331 print <<EOM ;
332SKIPPED
333# getsockname not present
334# getpeername not present
335# gethostbyname not present
336# gethostbyaddr not present
337# gethostent not present
338# getnetbyname not present
339# getnetbyaddr not present
340# getnetent not present
341# getprotobyname not present
342# getprotobynumber not present
343# getprotoent not present
344# getservbyname not present
345# getservbyport not present
346# getservent not present
347EOM
348 exit
349} }
350getsockname STDIN ; # OP_GETSOCKNAME
351getpeername STDIN ; # OP_GETPEERNAME
352gethostbyname 1 ; # OP_GHBYNAME
353gethostbyaddr 1,2; # OP_GHBYADDR
354gethostent ; # OP_GHOSTENT
355getnetbyname 1 ; # OP_GNBYNAME
356getnetbyaddr 1,2 ; # OP_GNBYADDR
357getnetent ; # OP_GNETENT
358getprotobyname 1; # OP_GPBYNAME
359getprotobynumber 1; # OP_GPBYNUMBER
360getprotoent ; # OP_GPROTOENT
361getservbyname 1,2; # OP_GSBYNAME
362getservbyport 1,2; # OP_GSBYPORT
363getservent ; # OP_GSERVENT
364EXPECT
365Useless use of getsockname in void context at - line 24.
366Useless use of getpeername in void context at - line 25.
367Useless use of gethostbyname in void context at - line 26.
368Useless use of gethostbyaddr in void context at - line 27.
369Useless use of gethostent in void context at - line 28.
370Useless use of getnetbyname in void context at - line 29.
371Useless use of getnetbyaddr in void context at - line 30.
372Useless use of getnetent in void context at - line 31.
373Useless use of getprotobyname in void context at - line 32.
374Useless use of getprotobynumber in void context at - line 33.
375Useless use of getprotoent in void context at - line 34.
376Useless use of getservbyname in void context at - line 35.
377Useless use of getservbyport in void context at - line 36.
378Useless use of getservent in void context at - line 37.
379########
380# op.c
381use warning 'void' ;
382*a ; # OP_RV2GV
383$a ; # OP_RV2SV
384@a ; # OP_RV2AV
385%a ; # OP_RV2HV
386EXPECT
387Useless use of a variable in void context at - line 3.
388Useless use of a variable in void context at - line 4.
389Useless use of a variable in void context at - line 5.
390Useless use of a variable in void context at - line 6.
391########
392# op.c
393use warning 'void' ;
394"abc"; # OP_CONST
3957 ; # OP_CONST
396EXPECT
397Useless use of a constant in void context at - line 3.
398Useless use of a constant in void context at - line 4.
399########
400# op.c
401use warning 'unsafe' ;
402my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
403@a =~ /abc/ ;
404@a =~ s/a/b/ ;
405@a =~ tr/a/b/ ;
406@$b =~ /abc/ ;
407@$b =~ s/a/b/ ;
408@$b =~ tr/a/b/ ;
409%a =~ /abc/ ;
410%a =~ s/a/b/ ;
411%a =~ tr/a/b/ ;
412%$c =~ /abc/ ;
413%$c =~ s/a/b/ ;
414%$c =~ tr/a/b/ ;
415EXPECT
416Applying pattern match to @array will act on scalar(@array) at - line 4.
417Applying substitution to @array will act on scalar(@array) at - line 5.
418Can't modify private array in substitution at - line 5, near "s/a/b/ ;"
419Applying character translation to @array will act on scalar(@array) at - line 6.
420Applying pattern match to @array will act on scalar(@array) at - line 7.
421Applying substitution to @array will act on scalar(@array) at - line 8.
422Applying character translation to @array will act on scalar(@array) at - line 9.
423Applying pattern match to %hash will act on scalar(%hash) at - line 10.
424Applying substitution to %hash will act on scalar(%hash) at - line 11.
425Applying character translation to %hash will act on scalar(%hash) at - line 12.
426Applying pattern match to %hash will act on scalar(%hash) at - line 13.
427Applying substitution to %hash will act on scalar(%hash) at - line 14.
428Applying character translation to %hash will act on scalar(%hash) at - line 15.
429Execution of - aborted due to compilation errors.
430########
431# op.c
432use warning 'syntax' ;
433my $a, $b = (1,2);
434EXPECT
435Parens missing around "my" list at - line 3.
436########
437# op.c
438use warning 'syntax' ;
439local $a, $b = (1,2);
440EXPECT
441Parens missing around "local" list at - line 3.
442########
443# op.c
444use warning 'syntax' ;
445print (ABC || 1) ;
446EXPECT
447Probable precedence problem on logical or at - line 3.
448########
449--FILE-- abc
450
451--FILE--
452# op.c
453use warning 'unsafe' ;
454open FH, "<abc" ;
455$x = 1 if $x = <FH> ;
456EXPECT
457Value of <HANDLE> construct can be "0"; test with defined() at - line 4.
458########
459# op.c
460use warning 'unsafe' ;
461opendir FH, "." ;
462$x = 1 if $x = readdir FH ;
463closedir FH ;
464EXPECT
465Value of readdir() operator can be "0"; test with defined() at - line 4.
466########
467# op.c
468use warning 'unsafe' ;
469$x = 1 if $x = <*> ;
470EXPECT
471Value of glob construct can be "0"; test with defined() at - line 3.
472########
473# op.c
474use warning 'unsafe' ;
475%a = (1,2,3,4) ;
476$x = 1 if $x = each %a ;
477EXPECT
478Value of each() operator can be "0"; test with defined() at - line 4.
479########
480# op.c
481use warning 'unsafe' ;
482$x = 1 while $x = <*> and 0 ;
483EXPECT
484Value of glob construct can be "0"; test with defined() at - line 3.
485########
486# op.c
487use warning 'unsafe' ;
488opendir FH, "." ;
489$x = 1 while $x = readdir FH and 0 ;
490closedir FH ;
491EXPECT
492Value of readdir() operator can be "0"; test with defined() at - line 4.
493########
494# op.c
495use warning 'redefine' ;
496sub fred {}
497sub fred {}
498EXPECT
499Subroutine fred redefined at - line 4.
500########
501# op.c
502use warning 'redefine' ;
503sub fred () { 1 }
504sub fred () { 1 }
505EXPECT
506Constant subroutine fred redefined at - line 4.
507########
508# op.c
509use warning 'redefine' ;
510format FRED =
511.
512format FRED =
513.
514EXPECT
515Format FRED redefined at - line 5.
516########
517# op.c
518use warning 'syntax' ;
519push FRED;
520EXPECT
521Array @FRED missing the @ in argument 1 of push() at - line 3.
522########
523# op.c
524use warning 'syntax' ;
525@a = keys FRED ;
526EXPECT
527Hash %FRED missing the % in argument 1 of keys() at - line 3.
528########
529# op.c
530use warning 'syntax' ;
531exec "true" ;
532my $a
533EXPECT
534Statement unlikely to be reached at - line 4.
535(Maybe you meant system() when you said exec()?)