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