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