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