This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #94390] Optimised numeric sort should warn for nan
[perl5.git] / t / lib / warnings / op
1   op.c          AOK
2
3      Found = in conditional, should be ==
4         1 if $a = 1 ;
5
6      Useless use of time in void context
7      Useless use of a variable in void context
8      Useless use of a constant in void context
9         time ;
10         $a ;
11         "abc"
12
13      Useless use of sort in scalar context
14         my $x = sort (2,1,3);
15
16      Applying %s to %s will act on scalar(%s)
17         my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
18         @a =~ /abc/ ;
19         @a =~ s/a/b/ ;
20         @a =~ tr/a/b/ ;
21         @$b =~ /abc/ ;
22         @$b =~ s/a/b/ ;
23         @$b =~ tr/a/b/ ;
24         %a =~ /abc/ ;
25         %a =~ s/a/b/ ;
26         %a =~ tr/a/b/ ;
27         %$c =~ /abc/ ;
28         %$c =~ s/a/b/ ;
29         %$c =~ tr/a/b/ ;
30
31
32      Parentheses missing around "my" list at -e line 1.
33        my $a, $b = (1,2);
34  
35      Parentheses missing around "local" list at -e line 1.
36        local $a, $b = (1,2);
37  
38      Bareword found in conditional at -e line 1.
39        use warnings 'bareword'; my $x = print(ABC || 1);
40  
41      Value of %s may be \"0\"; use \"defined\" 
42         $x = 1 if $x = <FH> ;
43         $x = 1 while $x = <FH> ;
44
45      Subroutine fred redefined at -e line 1.
46        sub fred{1;} sub fred{1;}
47  
48      Constant subroutine %s redefined 
49         sub fred() {1;} sub fred() {1;}
50  
51      Format FRED redefined at /tmp/x line 5.
52        format FRED =
53        .
54        format FRED =
55        .
56  
57      Array @%s missing the @ in argument %d of %s() 
58         push fred ;
59  
60      Hash %%%s missing the %% in argument %d of %s() 
61         keys joe ;
62  
63      Statement unlikely to be reached
64         (Maybe you meant system() when you said exec()?
65         exec "true" ; my $a
66
67      defined(@array) is deprecated
68         (Maybe you should just omit the defined()?)
69         my @a ; defined @a ;
70         defined (@a = (1,2,3)) ;
71
72      defined(%hash) is deprecated
73         (Maybe you should just omit the defined()?)
74         my %h ; defined %h ;
75     
76      /---/ should probably be written as "---"
77         join(/---/, @foo);
78
79     %s() called too early to check prototype            [Perl_peep]
80         fred() ; sub fred ($$) {}
81
82
83     Package `%s' not found (did you use the incorrect case?)
84
85     Use of /g modifier is meaningless in split
86
87     Possible precedence problem on bitwise %c operator  [Perl_ck_bitop]
88
89     Mandatory Warnings 
90     ------------------
91     Prototype mismatch:         [cv_ckproto]
92         sub fred() ;
93         sub fred($) {}
94
95     Runaway prototype           [newSUB]        TODO
96     oops: oopsAV                [oopsAV]        TODO
97     oops: oopsHV                [oopsHV]        TODO
98     
99 __END__
100 # op.c
101 use warnings 'syntax' ;
102 1 if $a = 1 ;
103 no warnings 'syntax' ;
104 1 if $a = 1 ;
105 EXPECT
106 Found = in conditional, should be == at - line 3.
107 ########
108 # op.c
109 use warnings 'syntax' ;
110 use constant foo => 1;
111 1 if $a = foo ;
112 no warnings 'syntax' ;
113 1 if $a = foo ;
114 EXPECT
115 ########
116 # op.c
117 my (@foo, %foo);
118 %main::foo->{"bar"};
119 %foo->{"bar"};
120 @main::foo->[23];
121 @foo->[23];
122 $main::foo = {}; %$main::foo->{"bar"};
123 $foo = {}; %$foo->{"bar"};
124 $main::foo = []; @$main::foo->[34];
125 $foo = []; @$foo->[34];
126 no warnings 'deprecated';
127 %main::foo->{"bar"};
128 %foo->{"bar"};
129 @main::foo->[23];
130 @foo->[23];
131 $main::foo = {}; %$main::foo->{"bar"};
132 $foo = {}; %$foo->{"bar"};
133 $main::foo = []; @$main::foo->[34];
134 $foo = []; @$foo->[34];
135 EXPECT
136 Using a hash as a reference is deprecated at - line 3.
137 Using a hash as a reference is deprecated at - line 4.
138 Using an array as a reference is deprecated at - line 5.
139 Using an array as a reference is deprecated at - line 6.
140 Using a hash as a reference is deprecated at - line 7.
141 Using a hash as a reference is deprecated at - line 8.
142 Using an array as a reference is deprecated at - line 9.
143 Using an array as a reference is deprecated at - line 10.
144 ########
145 # op.c
146 use warnings 'void' ; close STDIN ;
147 1 x 3 ;                 # OP_REPEAT
148                         # OP_GVSV
149 wantarray ;             # OP_WANTARRAY
150                         # OP_GV
151                         # OP_PADSV
152                         # OP_PADAV
153                         # OP_PADHV
154                         # OP_PADANY
155                         # OP_AV2ARYLEN
156 ref ;                   # OP_REF
157 \@a ;                   # OP_REFGEN
158 \$a ;                   # OP_SREFGEN
159 defined $a ;            # OP_DEFINED
160 hex $a ;                # OP_HEX
161 oct $a ;                # OP_OCT
162 length $a ;             # OP_LENGTH
163 substr $a,1 ;           # OP_SUBSTR
164 vec $a,1,2 ;            # OP_VEC
165 index $a,1,2 ;          # OP_INDEX
166 rindex $a,1,2 ;         # OP_RINDEX
167 sprintf $a ;            # OP_SPRINTF
168 $a[0] ;                 # OP_AELEM
169                         # OP_AELEMFAST
170 @a[0] ;                 # OP_ASLICE
171 #values %a ;            # OP_VALUES
172 #keys %a ;              # OP_KEYS
173 $a{0} ;                 # OP_HELEM
174 @a{0} ;                 # OP_HSLICE
175 unpack "a", "a" ;       # OP_UNPACK
176 pack $a,"" ;            # OP_PACK
177 join "" ;               # OP_JOIN
178 (@a)[0,1] ;             # OP_LSLICE
179                         # OP_ANONLIST
180                         # OP_ANONHASH
181 sort(1,2) ;             # OP_SORT
182 reverse(1,2) ;          # OP_REVERSE
183                         # OP_RANGE
184                         # OP_FLIP
185 (1 ..2) ;               # OP_FLOP
186 caller ;                # OP_CALLER
187 fileno STDIN ;          # OP_FILENO
188 eof STDIN ;             # OP_EOF
189 tell STDIN ;            # OP_TELL
190 readlink 1;             # OP_READLINK
191 time ;                  # OP_TIME
192 localtime ;             # OP_LOCALTIME
193 gmtime ;                # OP_GMTIME
194 eval { getgrnam 1 };    # OP_GGRNAM
195 eval { getgrgid 1 };    # OP_GGRGID
196 eval { getpwnam 1 };    # OP_GPWNAM
197 eval { getpwuid 1 };    # OP_GPWUID
198 prototype "foo";        # OP_PROTOTYPE
199 $a ~~ $b;               # OP_SMARTMATCH
200 $a <=> $b;              # OP_NCMP
201 EXPECT
202 Useless use of repeat (x) in void context at - line 3.
203 Useless use of wantarray in void context at - line 5.
204 Useless use of reference-type operator in void context at - line 12.
205 Useless use of reference constructor in void context at - line 13.
206 Useless use of single ref constructor in void context at - line 14.
207 Useless use of defined operator in void context at - line 15.
208 Useless use of hex in void context at - line 16.
209 Useless use of oct in void context at - line 17.
210 Useless use of length in void context at - line 18.
211 Useless use of substr in void context at - line 19.
212 Useless use of vec in void context at - line 20.
213 Useless use of index in void context at - line 21.
214 Useless use of rindex in void context at - line 22.
215 Useless use of sprintf in void context at - line 23.
216 Useless use of array element in void context at - line 24.
217 Useless use of array slice in void context at - line 26.
218 Useless use of hash element in void context at - line 29.
219 Useless use of hash slice in void context at - line 30.
220 Useless use of unpack in void context at - line 31.
221 Useless use of pack in void context at - line 32.
222 Useless use of join or string in void context at - line 33.
223 Useless use of list slice in void context at - line 34.
224 Useless use of sort in void context at - line 37.
225 Useless use of reverse in void context at - line 38.
226 Useless use of range (or flop) in void context at - line 41.
227 Useless use of caller in void context at - line 42.
228 Useless use of fileno in void context at - line 43.
229 Useless use of eof in void context at - line 44.
230 Useless use of tell in void context at - line 45.
231 Useless use of readlink in void context at - line 46.
232 Useless use of time in void context at - line 47.
233 Useless use of localtime in void context at - line 48.
234 Useless use of gmtime in void context at - line 49.
235 Useless use of getgrnam in void context at - line 50.
236 Useless use of getgrgid in void context at - line 51.
237 Useless use of getpwnam in void context at - line 52.
238 Useless use of getpwuid in void context at - line 53.
239 Useless use of subroutine prototype in void context at - line 54.
240 Useless use of smart match in void context at - line 55.
241 Useless use of numeric comparison (<=>) in void context at - line 56.
242 ########
243 # op.c
244 use warnings 'void' ; close STDIN ;
245 my $x = sort (2,1,3);
246 no warnings 'void' ;
247 $x = sort (2,1,3);
248 EXPECT
249 Useless use of sort in scalar context at - line 3.
250 ########
251 # op.c
252 no warnings 'void' ; close STDIN ;
253 1 x 3 ;                 # OP_REPEAT
254                         # OP_GVSV
255 wantarray ;             # OP_WANTARRAY
256                         # OP_GV
257                         # OP_PADSV
258                         # OP_PADAV
259                         # OP_PADHV
260                         # OP_PADANY
261                         # OP_AV2ARYLEN
262 ref ;                   # OP_REF
263 \@a ;                   # OP_REFGEN
264 \$a ;                   # OP_SREFGEN
265 defined $a ;            # OP_DEFINED
266 hex $a ;                # OP_HEX
267 oct $a ;                # OP_OCT
268 length $a ;             # OP_LENGTH
269 substr $a,1 ;           # OP_SUBSTR
270 vec $a,1,2 ;            # OP_VEC
271 index $a,1,2 ;          # OP_INDEX
272 rindex $a,1,2 ;         # OP_RINDEX
273 sprintf $a ;            # OP_SPRINTF
274 $a[0] ;                 # OP_AELEM
275                         # OP_AELEMFAST
276 @a[0] ;                 # OP_ASLICE
277 #values %a ;            # OP_VALUES
278 #keys %a ;              # OP_KEYS
279 $a{0} ;                 # OP_HELEM
280 @a{0} ;                 # OP_HSLICE
281 unpack "a", "a" ;       # OP_UNPACK
282 pack $a,"" ;            # OP_PACK
283 join "" ;               # OP_JOIN
284 (@a)[0,1] ;             # OP_LSLICE
285                         # OP_ANONLIST
286                         # OP_ANONHASH
287 sort(1,2) ;             # OP_SORT
288 reverse(1,2) ;          # OP_REVERSE
289                         # OP_RANGE
290                         # OP_FLIP
291 (1 ..2) ;               # OP_FLOP
292 caller ;                # OP_CALLER
293 fileno STDIN ;          # OP_FILENO
294 eof STDIN ;             # OP_EOF
295 tell STDIN ;            # OP_TELL
296 readlink 1;             # OP_READLINK
297 time ;                  # OP_TIME
298 localtime ;             # OP_LOCALTIME
299 gmtime ;                # OP_GMTIME
300 eval { getgrnam 1 };    # OP_GGRNAM
301 eval { getgrgid 1 };    # OP_GGRGID
302 eval { getpwnam 1 };    # OP_GPWNAM
303 eval { getpwuid 1 };    # OP_GPWUID
304 prototype "foo";        # OP_PROTOTYPE
305 EXPECT
306 ########
307 # op.c
308 use warnings 'void' ;
309 for (@{[0]}) { "$_" }           # check warning isn't duplicated
310 no warnings 'void' ;
311 for (@{[0]}) { "$_" }           # check warning isn't duplicated
312 EXPECT
313 Useless use of string in void context at - line 3.
314 ########
315 # op.c
316 use warnings 'void' ;
317 use Config ;
318 BEGIN {
319     if ( ! $Config{d_telldir}) {
320         print <<EOM ;
321 SKIPPED
322 # telldir not present
323 EOM
324         exit 
325     }
326 }
327 telldir 1 ;             # OP_TELLDIR
328 no warnings 'void' ;
329 telldir 1 ;             # OP_TELLDIR
330 EXPECT
331 Useless use of telldir in void context at - line 13.
332 ########
333 # op.c
334 use warnings 'void' ;
335 use Config ;
336 BEGIN {
337     if ( ! $Config{d_getppid}) {
338         print <<EOM ;
339 SKIPPED
340 # getppid not present
341 EOM
342         exit 
343     }
344 }
345 getppid ;               # OP_GETPPID
346 no warnings 'void' ;
347 getppid ;               # OP_GETPPID
348 EXPECT
349 Useless use of getppid in void context at - line 13.
350 ########
351 # op.c
352 use warnings 'void' ;
353 use Config ;
354 BEGIN {
355     if ( ! $Config{d_getpgrp}) {
356         print <<EOM ;
357 SKIPPED
358 # getpgrp not present
359 EOM
360         exit 
361     }
362 }
363 getpgrp ;               # OP_GETPGRP
364 no warnings 'void' ;
365 getpgrp ;               # OP_GETPGRP
366 EXPECT
367 Useless use of getpgrp in void context at - line 13.
368 ########
369 # op.c
370 use warnings 'void' ;
371 use Config ;
372 BEGIN {
373     if ( ! $Config{d_times}) {
374         print <<EOM ;
375 SKIPPED
376 # times not present
377 EOM
378         exit 
379     }
380 }
381 times ;                 # OP_TMS
382 no warnings 'void' ;
383 times ;                 # OP_TMS
384 EXPECT
385 Useless use of times in void context at - line 13.
386 ########
387 # op.c
388 use warnings 'void' ;
389 use Config ;
390 BEGIN {
391     if ( ! $Config{d_getprior} or $^O eq 'os2') { # Locks before fixpak22
392         print <<EOM ;
393 SKIPPED
394 # getpriority not present
395 EOM
396         exit 
397     }
398 }
399 getpriority 1,2;        # OP_GETPRIORITY
400 no warnings 'void' ;
401 getpriority 1,2;        # OP_GETPRIORITY
402 EXPECT
403 Useless use of getpriority in void context at - line 13.
404 ########
405 # op.c
406 use warnings 'void' ;
407 use Config ;
408 BEGIN {
409     if ( ! $Config{d_getlogin}) {
410         print <<EOM ;
411 SKIPPED
412 # getlogin not present
413 EOM
414         exit 
415     }
416 }
417 getlogin ;                      # OP_GETLOGIN
418 no warnings 'void' ;
419 getlogin ;                      # OP_GETLOGIN
420 EXPECT
421 Useless use of getlogin in void context at - line 13.
422 ########
423 # op.c
424 use warnings 'void' ;
425 use Config ; BEGIN {
426 if ( ! $Config{d_socket}) {
427     print <<EOM ;
428 SKIPPED
429 # getsockname not present
430 # getpeername not present
431 # gethostbyname not present
432 # gethostbyaddr not present
433 # gethostent not present
434 # getnetbyname not present
435 # getnetbyaddr not present
436 # getnetent not present
437 # getprotobyname not present
438 # getprotobynumber not present
439 # getprotoent not present
440 # getservbyname not present
441 # getservbyport not present
442 # getservent not present
443 EOM
444     exit 
445 } }
446 getsockname STDIN ;     # OP_GETSOCKNAME
447 getpeername STDIN ;     # OP_GETPEERNAME
448 gethostbyname 1 ;       # OP_GHBYNAME
449 gethostbyaddr 1,2;      # OP_GHBYADDR
450 gethostent ;            # OP_GHOSTENT
451 getnetbyname 1 ;        # OP_GNBYNAME
452 getnetbyaddr 1,2 ;      # OP_GNBYADDR
453 getnetent ;             # OP_GNETENT
454 getprotobyname 1;       # OP_GPBYNAME
455 getprotobynumber 1;     # OP_GPBYNUMBER
456 getprotoent ;           # OP_GPROTOENT
457 getservbyname 1,2;      # OP_GSBYNAME
458 getservbyport 1,2;      # OP_GSBYPORT
459 getservent ;            # OP_GSERVENT
460
461 no warnings 'void' ;
462 getsockname STDIN ;     # OP_GETSOCKNAME
463 getpeername STDIN ;     # OP_GETPEERNAME
464 gethostbyname 1 ;       # OP_GHBYNAME
465 gethostbyaddr 1,2;      # OP_GHBYADDR
466 gethostent ;            # OP_GHOSTENT
467 getnetbyname 1 ;        # OP_GNBYNAME
468 getnetbyaddr 1,2 ;      # OP_GNBYADDR
469 getnetent ;             # OP_GNETENT
470 getprotobyname 1;       # OP_GPBYNAME
471 getprotobynumber 1;     # OP_GPBYNUMBER
472 getprotoent ;           # OP_GPROTOENT
473 getservbyname 1,2;      # OP_GSBYNAME
474 getservbyport 1,2;      # OP_GSBYPORT
475 getservent ;            # OP_GSERVENT
476 INIT {
477    # some functions may not be there, so we exit without running
478    exit;
479 }
480 EXPECT
481 Useless use of getsockname in void context at - line 24.
482 Useless use of getpeername in void context at - line 25.
483 Useless use of gethostbyname in void context at - line 26.
484 Useless use of gethostbyaddr in void context at - line 27.
485 Useless use of gethostent in void context at - line 28.
486 Useless use of getnetbyname in void context at - line 29.
487 Useless use of getnetbyaddr in void context at - line 30.
488 Useless use of getnetent in void context at - line 31.
489 Useless use of getprotobyname in void context at - line 32.
490 Useless use of getprotobynumber in void context at - line 33.
491 Useless use of getprotoent in void context at - line 34.
492 Useless use of getservbyname in void context at - line 35.
493 Useless use of getservbyport in void context at - line 36.
494 Useless use of getservent in void context at - line 37.
495 ########
496 # op.c
497 use warnings 'void' ;
498 *a ; # OP_RV2GV
499 $a ; # OP_RV2SV
500 @a ; # OP_RV2AV
501 %a ; # OP_RV2HV
502 no warnings 'void' ;
503 *a ; # OP_RV2GV
504 $a ; # OP_RV2SV
505 @a ; # OP_RV2AV
506 %a ; # OP_RV2HV
507 EXPECT
508 Useless use of a variable in void context at - line 3.
509 Useless use of a variable in void context at - line 4.
510 Useless use of a variable in void context at - line 5.
511 Useless use of a variable in void context at - line 6.
512 ########
513 # op.c
514 use warnings 'void' ;
515 "abc"; # OP_CONST
516 7 ; # OP_CONST
517 "x" . "y"; # optimized to OP_CONST
518 2 + 2; # optimized to OP_CONST
519 use constant U => undef;
520 U;
521 5 || print "bad\n";     # test OPpCONST_SHORTCIRCUIT
522 print "boo\n" if U;     # test OPpCONST_SHORTCIRCUIT
523 no warnings 'void' ;
524 "abc"; # OP_CONST
525 7 ; # OP_CONST
526 "x" . "y"; # optimized to OP_CONST
527 2 + 2; # optimized to OP_CONST
528 EXPECT
529 Useless use of a constant (abc) in void context at - line 3.
530 Useless use of a constant (7) in void context at - line 4.
531 Useless use of a constant (xy) in void context at - line 5.
532 Useless use of a constant (4) in void context at - line 6.
533 Useless use of a constant (undef) in void context at - line 8.
534 ########
535 # op.c
536 use utf8;
537 use open qw( :utf8 :std );
538 use warnings 'void' ;
539 "àḆc"; # OP_CONST
540 "Ẋ" . "ƴ"; # optimized to OP_CONST
541 FOO;     # Bareword optimized to OP_CONST
542 use constant ů => undef;
543 ů;
544 5 || print "bad\n";     # test OPpCONST_SHORTCIRCUIT
545 print "boo\n" if ů;    # test OPpCONST_SHORTCIRCUIT
546 no warnings 'void' ;
547 "àḆc"; # OP_CONST
548 "Ẋ" . "ƴ"; # optimized to OP_CONST
549 EXPECT
550 Useless use of a constant (àḆc) in void context at - line 5.
551 Useless use of a constant (Ẋƴ) in void context at - line 6.
552 Useless use of a constant (FOO) in void context at - line 7.
553 Useless use of a constant (undef) in void context at - line 9.
554 ########
555 # op.c
556 #
557 use warnings 'misc' ;
558 my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;my $d = 'test';
559 @a =~ /abc/ ;
560 @a =~ s/a/b/ ;
561 @a =~ tr/a/b/ ;
562 @$b =~ /abc/ ;
563 @$b =~ s/a/b/ ;
564 @$b =~ tr/a/b/ ;
565 %a =~ /abc/ ;
566 %a =~ s/a/b/ ;
567 %a =~ tr/a/b/ ;
568 %$c =~ /abc/ ;
569 %$c =~ s/a/b/ ;
570 %$c =~ tr/a/b/ ;
571 $d =~ tr/a/b/d ;
572 $d =~ tr/a/bc/;
573 {
574 no warnings 'misc' ;
575 my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; my $d = 'test';
576 @a =~ /abc/ ;
577 @a =~ s/a/b/ ;
578 @a =~ tr/a/b/ ;
579 @$b =~ /abc/ ;
580 @$b =~ s/a/b/ ;
581 @$b =~ tr/a/b/ ;
582 %a =~ /abc/ ;
583 %a =~ s/a/b/ ;
584 %a =~ tr/a/b/ ;
585 %$c =~ /abc/ ;
586 %$c =~ s/a/b/ ;
587 %$c =~ tr/a/b/ ;
588 $d =~ tr/a/b/d ;
589 $d =~ tr/a/bc/ ;
590 }
591 EXPECT
592 Applying pattern match (m//) to @array will act on scalar(@array) at - line 5.
593 Applying substitution (s///) to @array will act on scalar(@array) at - line 6.
594 Applying transliteration (tr///) to @array will act on scalar(@array) at - line 7.
595 Applying pattern match (m//) to @array will act on scalar(@array) at - line 8.
596 Applying substitution (s///) to @array will act on scalar(@array) at - line 9.
597 Applying transliteration (tr///) to @array will act on scalar(@array) at - line 10.
598 Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 11.
599 Applying substitution (s///) to %hash will act on scalar(%hash) at - line 12.
600 Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 13.
601 Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 14.
602 Applying substitution (s///) to %hash will act on scalar(%hash) at - line 15.
603 Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 16.
604 Useless use of /d modifier in transliteration operator at - line 17.
605 Replacement list is longer than search list at - line 18.
606 Can't modify private array in substitution (s///) at - line 6, near "s/a/b/ ;"
607 BEGIN not safe after errors--compilation aborted at - line 20.
608 ########
609 # op.c
610 use warnings 'parenthesis' ;
611 my $a, $b = (1,2);
612 my @foo,%bar,   $quux; # there's a TAB here
613 my $x, $y or print;
614 no warnings 'parenthesis' ;
615 my $c, $d = (1,2);
616 EXPECT
617 Parentheses missing around "my" list at - line 3.
618 Parentheses missing around "my" list at - line 4.
619 ########
620 # op.c
621 use warnings 'parenthesis' ;
622 our $a, $b = (1,2);
623 no warnings 'parenthesis' ;
624 our $c, $d = (1,2);
625 EXPECT
626 Parentheses missing around "our" list at - line 3.
627 ########
628 # op.c
629 use warnings 'parenthesis' ;
630 local $a, $b = (1,2);
631 local *f, *g;
632 no warnings 'parenthesis' ;
633 local $c, $d = (1,2);
634 EXPECT
635 Parentheses missing around "local" list at - line 3.
636 Parentheses missing around "local" list at - line 4.
637 ########
638 # op.c
639 use warnings 'bareword' ;
640 print (ABC || 1) ;
641 no warnings 'bareword' ;
642 print (ABC || 1) ;
643 EXPECT
644 Bareword found in conditional at - line 3.
645 ########
646 --FILE-- abc
647
648 --FILE--
649 # op.c
650 use warnings 'misc' ;
651 open FH, "<abc" ;
652 $x = 1 if $x = <FH> ;
653 no warnings 'misc' ;
654 $x = 1 if $x = <FH> ;
655 EXPECT
656 Value of <HANDLE> construct can be "0"; test with defined() at - line 4.
657 ########
658 # op.c
659 use warnings 'misc' ;
660 opendir FH, "." ;
661 $x = 1 if $x = readdir FH ;
662 no warnings 'misc' ;
663 $x = 1 if $x = readdir FH ;
664 closedir FH ;
665 EXPECT
666 Value of readdir() operator can be "0"; test with defined() at - line 4.
667 ########
668 # op.c
669 use warnings 'misc' ;
670 $x = 1 if $x = <*> ;
671 no warnings 'misc' ;
672 $x = 1 if $x = <*> ;
673 EXPECT
674 Value of glob construct can be "0"; test with defined() at - line 3.
675 ########
676 # op.c
677 use warnings 'misc' ;
678 %a = (1,2,3,4) ;
679 $x = 1 if $x = each %a ;
680 no warnings 'misc' ;
681 $x = 1 if $x = each %a ;
682 EXPECT
683 Value of each() operator can be "0"; test with defined() at - line 4.
684 ########
685 # op.c
686 use warnings 'misc' ;
687 $x = 1 while $x = <*> and 0 ;
688 no warnings 'misc' ;
689 $x = 1 while $x = <*> and 0 ;
690 EXPECT
691 Value of glob construct can be "0"; test with defined() at - line 3.
692 ########
693 # op.c
694 use warnings 'misc' ;
695 opendir FH, "." ;
696 $x = 1 while $x = readdir FH and 0 ;
697 no warnings 'misc' ;
698 $x = 1 while $x = readdir FH and 0 ;
699 closedir FH ;
700 EXPECT
701 Value of readdir() operator can be "0"; test with defined() at - line 4.
702 ########
703 # op.c
704 use warnings 'misc';
705 open FH, "<abc";
706 ($_ = <FH>) // ($_ = 1);
707 opendir DH, ".";
708 %a = (1,2,3,4) ;
709 EXPECT
710 ########
711 # op.c
712 use warnings 'redefine' ;
713 sub fred {}
714 sub fred {}
715 no warnings 'redefine' ;
716 sub fred {}
717 EXPECT
718 Subroutine fred redefined at - line 4.
719 ########
720 # op.c
721 use warnings 'redefine' ;
722 sub fred () { 1 }
723 sub fred () { 1 }
724 no warnings 'redefine' ;
725 sub fred () { 1 }
726 EXPECT
727 Constant subroutine fred redefined at - line 4.
728 ########
729 # op.c
730 no warnings 'redefine' ;
731 sub fred () { 1 }
732 sub fred () { 2 }
733 EXPECT
734 Constant subroutine fred redefined at - line 4.
735 ########
736 # op.c
737 no warnings 'redefine' ;
738 sub fred () { 1 }
739 *fred = sub () { 2 };
740 EXPECT
741 Constant subroutine main::fred redefined at - line 4.
742 ########
743 # op.c
744 use warnings 'redefine' ;
745 format FRED =
746 .
747 format FRED =
748 .
749 no warnings 'redefine' ;
750 format FRED =
751 .
752 EXPECT
753 Format FRED redefined at - line 5.
754 ########
755 # op.c
756 push FRED;
757 no warnings 'deprecated' ;
758 push FRED;
759 EXPECT
760 Array @FRED missing the @ in argument 1 of push() at - line 2.
761 ########
762 # op.c
763 @a = keys FRED ;
764 no warnings 'deprecated' ;
765 @a = keys FRED ;
766 EXPECT
767 Hash %FRED missing the % in argument 1 of keys() at - line 2.
768 ########
769 # op.c
770 use warnings 'syntax' ;
771 exec "$^X -e 1" ; 
772 my $a
773 EXPECT
774 Statement unlikely to be reached at - line 4.
775         (Maybe you meant system() when you said exec()?)
776 ########
777 # op.c, no warning if exec isn't a statement.
778 use warnings 'syntax' ;
779 $a || exec "$^X -e 1" ;
780 my $a
781 EXPECT
782 ########
783 # op.c
784 my @a; defined(@a);
785 EXPECT
786 defined(@array) is deprecated at - line 2.
787         (Maybe you should just omit the defined()?)
788 ########
789 # op.c
790 defined(@a = (1,2,3));
791 EXPECT
792 defined(@array) is deprecated at - line 2.
793         (Maybe you should just omit the defined()?)
794 ########
795 # op.c
796 my %h; defined(%h);
797 EXPECT
798 defined(%hash) is deprecated at - line 2.
799         (Maybe you should just omit the defined()?)
800 ########
801 # op.c
802 no warnings 'syntax' ;
803 exec "$^X -e 1" ; 
804 my $a
805 EXPECT
806
807 ########
808 # op.c
809 sub fred();
810 sub fred($) {}
811 EXPECT
812 Prototype mismatch: sub main::fred () vs ($) at - line 3.
813 ########
814 # op.c
815 use utf8;
816 use open qw( :utf8 :std );
817 sub frèd();
818 sub frèd($) {}
819 EXPECT
820 Prototype mismatch: sub main::frèd () vs ($) at - line 5.
821 ########
822 # op.c
823 use utf8;
824 use open qw( :utf8 :std );
825 use warnings;
826 eval "sub fòò (\$\0) {}";
827 EXPECT
828 Illegal character in prototype for main::fòò : $\x{0} at (eval 1) line 1.
829 ########
830 # op.c
831 use utf8;
832 use open qw( :utf8 :std );
833 use warnings;
834 eval "sub foo (\0) {}";
835 EXPECT
836 Illegal character in prototype for main::foo : \x{0} at (eval 1) line 1.
837 ########
838 # op.c
839 use utf8;
840 use open qw( :utf8 :std );
841 use warnings;
842 BEGIN { $::{"foo"} = "\$\0L\351on" }
843 BEGIN { eval "sub foo (\$\0L\x{c3}\x{a9}on) {}"; }
844 EXPECT
845 Illegal character in prototype for main::foo : $\x{0}L... at (eval 1) line 1.
846 ########
847 # op.c
848 use utf8;
849 use open qw( :utf8 :std );
850 use warnings;
851 BEGIN { eval "sub foo (\0) {}"; }
852 EXPECT
853 Illegal character in prototype for main::foo : \x{0} at (eval 1) line 1.
854 ########
855 # op.c
856 use utf8;
857 use open qw( :utf8 :std );
858 use warnings;
859 BEGIN { $::{"foo"} = "\x{30cb}" }
860 BEGIN { eval "sub foo {}"; }
861 EXPECT
862 Prototype mismatch: sub main::foo (ニ) vs none at (eval 1) line 1.
863 ########
864 # op.c
865 $^W = 0 ;
866 sub fred() ;
867 sub fred($) {}
868 {
869     no warnings 'prototype' ;
870     sub Fred() ;
871     sub Fred($) {}
872     use warnings 'prototype' ;
873     sub freD() ;
874     sub freD($) {}
875 }
876 sub FRED() ;
877 sub FRED($) {}
878 EXPECT
879 Prototype mismatch: sub main::fred () vs ($) at - line 4.
880 Prototype mismatch: sub main::freD () vs ($) at - line 11.
881 Prototype mismatch: sub main::FRED () vs ($) at - line 14.
882 ########
883 # op.c
884 use warnings 'syntax' ;
885 join /---/, 'x', 'y', 'z';
886 EXPECT
887 /---/ should probably be written as "---" at - line 3.
888 ########
889 # op.c [Perl_peep]
890 use warnings 'prototype' ;
891 fred() ; 
892 sub fred ($$) {}
893 no warnings 'prototype' ;
894 joe() ; 
895 sub joe ($$) {}
896 EXPECT
897 main::fred() called too early to check prototype at - line 3.
898 ########
899 # op.c [Perl_newATTRSUB]
900 --FILE-- abc.pm
901 use warnings 'void' ;
902 BEGIN { $| = 1; print "in begin\n"; }
903 CHECK { print "in check\n"; }
904 INIT { print "in init\n"; }
905 END { print "in end\n"; }
906 print "in mainline\n";
907 1;
908 --FILE--
909 use abc;
910 delete $INC{"abc.pm"};
911 require abc;
912 do "abc.pm";
913 EXPECT
914 in begin
915 in mainline
916 in check
917 in init
918 in begin
919 Too late to run CHECK block at abc.pm line 3.
920 Too late to run INIT block at abc.pm line 4.
921 in mainline
922 in begin
923 Too late to run CHECK block at abc.pm line 3.
924 Too late to run INIT block at abc.pm line 4.
925 in mainline
926 in end
927 in end
928 in end
929 ########
930 # op.c [Perl_newATTRSUB]
931 --FILE-- abc.pm
932 no warnings 'void' ;
933 BEGIN { $| = 1; print "in begin\n"; }
934 CHECK { print "in check\n"; }
935 INIT { print "in init\n"; }
936 END { print "in end\n"; }
937 print "in mainline\n";
938 1;
939 --FILE--
940 require abc;
941 do "abc.pm";
942 EXPECT
943 in begin
944 in mainline
945 in begin
946 in mainline
947 in end
948 in end
949 ########
950 # op.c
951 my @x;
952 use warnings 'syntax' ;
953 push(@x);
954 unshift(@x);
955 no warnings 'syntax' ;
956 push(@x);
957 unshift(@x);
958 EXPECT
959 Useless use of push with no values at - line 4.
960 Useless use of unshift with no values at - line 5.
961 ########
962 # op.c
963 # 20020401 mjd@plover.com at suggestion of jfriedl@yahoo.com
964 use warnings 'regexp';
965 split /blah/g, "blah";
966 no warnings 'regexp';
967 split /blah/g, "blah";
968 EXPECT
969 Use of /g modifier is meaningless in split at - line 4.
970 ########
971 # op.c
972 use warnings 'precedence';
973 $a = $b & $c == $d;
974 $a = $b ^ $c != $d;
975 $a = $b | $c > $d;
976 $a = $b < $c & $d;
977 $a = $b >= $c ^ $d;
978 $a = $b <= $c | $d;
979 $a = $b <=> $c & $d;
980 $a &= $b == $c; $a |= $b == $c; $a ^= $b == $c; # shouldn't warn
981 no warnings 'precedence';
982 $a = $b & $c == $d;
983 $a = $b ^ $c != $d;
984 $a = $b | $c > $d;
985 $a = $b < $c & $d;
986 $a = $b >= $c ^ $d;
987 $a = $b <= $c | $d;
988 $a = $b <=> $c & $d;
989 EXPECT
990 Possible precedence problem on bitwise & operator at - line 3.
991 Possible precedence problem on bitwise ^ operator at - line 4.
992 Possible precedence problem on bitwise | operator at - line 5.
993 Possible precedence problem on bitwise & operator at - line 6.
994 Possible precedence problem on bitwise ^ operator at - line 7.
995 Possible precedence problem on bitwise | operator at - line 8.
996 Possible precedence problem on bitwise & operator at - line 9.
997 ########
998 # op.c
999 use integer;
1000 use warnings 'precedence';
1001 $a = $b & $c == $d;
1002 $a = $b ^ $c != $d;
1003 $a = $b | $c > $d;
1004 $a = $b < $c & $d;
1005 $a = $b >= $c ^ $d;
1006 $a = $b <= $c | $d;
1007 $a = $b <=> $c & $d;
1008 no warnings 'precedence';
1009 $a = $b & $c == $d;
1010 $a = $b ^ $c != $d;
1011 $a = $b | $c > $d;
1012 $a = $b < $c & $d;
1013 $a = $b >= $c ^ $d;
1014 $a = $b <= $c | $d;
1015 $a = $b <=> $c & $d;
1016 EXPECT
1017 Possible precedence problem on bitwise & operator at - line 4.
1018 Possible precedence problem on bitwise ^ operator at - line 5.
1019 Possible precedence problem on bitwise | operator at - line 6.
1020 Possible precedence problem on bitwise & operator at - line 7.
1021 Possible precedence problem on bitwise ^ operator at - line 8.
1022 Possible precedence problem on bitwise | operator at - line 9.
1023 Possible precedence problem on bitwise & operator at - line 10.
1024 ########
1025 # op.c
1026
1027 # ok    => local() has desired effect;
1028 # ignore=> local() silently ignored
1029
1030 use warnings 'syntax';
1031
1032 local(undef);           # OP_UNDEF              ignore
1033 sub lval : lvalue {};
1034 local(lval());          # OP_ENTERSUB
1035 local($x **= 1);        # OP_POW
1036 local($x *=  1);        # OP_MULTIPLY
1037 local($x /=  1);        # OP_DIVIDE
1038 local($x %=  1);        # OP_MODULO
1039 local($x x=  1);        # OP_REPEAT
1040 local($x +=  1);        # OP_ADD
1041 local($x -=  1);        # OP_SUBTRACT
1042 local($x .=  1);        # OP_CONCAT
1043 local($x <<= 1);        # OP_LEFT_SHIFT
1044 local($x >>= 1);        # OP_RIGHT_SHIFT
1045 local($x &=  1);        # OP_BIT_AND
1046 local($x ^=  1);        # OP_BIT_XOR
1047 local($x |=  1);        # OP_BIT_OR
1048 {
1049     use integer;
1050     local($x *= 1);     # OP_I_MULTIPLY
1051     local($x /= 1);     # OP_I_DIVIDE
1052     local($x %= 1);     # OP_I_MODULO
1053     local($x += 1);     # OP_I_ADD
1054     local($x -= 1);     # OP_I_SUBTRACT
1055 }
1056 local($x?$y:$z) = 1;    # OP_COND_EXPR          ok
1057 # these two are fatal run-time errors instead
1058 #local(@$a);            # OP_RV2AV              ok
1059 #local(%$a);            # OP_RV2HV              ok
1060 local(*a);              # OP_RV2GV              ok
1061 local(@a[1,2]);         # OP_ASLICE             ok
1062 local(@a{1,2});         # OP_HSLICE             ok
1063 local(@a = (1,2));      # OP_AASSIGN
1064 local($$x);             # OP_RV2SV              ok
1065 local($#a);             # OP_AV2ARYLEN
1066 local($x =   1);        # OP_SASSIGN
1067 local($x &&= 1);        # OP_ANDASSIGN
1068 local($x ||= 1);        # OP_ORASSIGN
1069 local($x //= 1);        # OP_DORASSIGN
1070 local($a[0]);           # OP_AELEMFAST          ok
1071
1072 local(substr($x,0,1));  # OP_SUBSTR
1073 local(pos($x));         # OP_POS
1074 local(vec($x,0,1));     # OP_VEC
1075 local($a[$b]);          # OP_AELEM              ok
1076 local($a{$b});          # OP_HELEM              ok
1077
1078 no warnings 'syntax';
1079 EXPECT
1080 Useless localization of subroutine entry at - line 10.
1081 Useless localization of exponentiation (**) at - line 11.
1082 Useless localization of multiplication (*) at - line 12.
1083 Useless localization of division (/) at - line 13.
1084 Useless localization of modulus (%) at - line 14.
1085 Useless localization of repeat (x) at - line 15.
1086 Useless localization of addition (+) at - line 16.
1087 Useless localization of subtraction (-) at - line 17.
1088 Useless localization of concatenation (.) or string at - line 18.
1089 Useless localization of left bitshift (<<) at - line 19.
1090 Useless localization of right bitshift (>>) at - line 20.
1091 Useless localization of bitwise and (&) at - line 21.
1092 Useless localization of bitwise xor (^) at - line 22.
1093 Useless localization of bitwise or (|) at - line 23.
1094 Useless localization of integer multiplication (*) at - line 26.
1095 Useless localization of integer division (/) at - line 27.
1096 Useless localization of integer modulus (%) at - line 28.
1097 Useless localization of integer addition (+) at - line 29.
1098 Useless localization of integer subtraction (-) at - line 30.
1099 Useless localization of list assignment at - line 39.
1100 Useless localization of array length at - line 41.
1101 Useless localization of scalar assignment at - line 42.
1102 Useless localization of logical and assignment (&&=) at - line 43.
1103 Useless localization of logical or assignment (||=) at - line 44.
1104 Useless localization of defined or assignment (//=) at - line 45.
1105 Useless localization of substr at - line 48.
1106 Useless localization of match position at - line 49.
1107 Useless localization of vec at - line 50.
1108 ########
1109 # op.c
1110 my $x1 if 0;
1111 my @x2 if 0;
1112 my %x3 if 0;
1113 my ($x4) if 0;
1114 my ($x5,@x6, %x7) if 0;
1115 0 && my $z1;
1116 0 && my (%z2);
1117 # these shouldn't warn
1118 our $x if 0;
1119 our $x unless 0;
1120 if (0) { my $w1 }
1121 if (my $w2) { $a=1 }
1122 if ($a && (my $w3 = 1)) {$a = 2}
1123
1124 EXPECT
1125 Deprecated use of my() in false conditional at - line 2.
1126 Deprecated use of my() in false conditional at - line 3.
1127 Deprecated use of my() in false conditional at - line 4.
1128 Deprecated use of my() in false conditional at - line 5.
1129 Deprecated use of my() in false conditional at - line 6.
1130 Deprecated use of my() in false conditional at - line 7.
1131 Deprecated use of my() in false conditional at - line 8.
1132 ########
1133 # op.c
1134 use warnings 'void';
1135 @x = split /y/, "z";
1136 $x = split /y/, "z";
1137      split /y/, "z";
1138 no warnings 'void';
1139 @x = split /y/, "z";
1140 $x = split /y/, "z";
1141      split /y/, "z";
1142 EXPECT
1143 Useless use of split in void context at - line 5.
1144 ########
1145 # op.c
1146 use warnings 'redefine' ;
1147 use utf8;
1148 use open qw( :utf8 :std );
1149 sub frèd {}
1150 sub frèd {}
1151 no warnings 'redefine' ;
1152 sub frèd {}
1153 EXPECT
1154 Subroutine frèd redefined at - line 6.
1155 ########
1156 # op.c
1157 use warnings 'redefine' ;
1158 use utf8;
1159 use open qw( :utf8 :std );
1160 sub frèd () { 1 }
1161 sub frèd () { 1 }
1162 no warnings 'redefine' ;
1163 sub frèd () { 1 }
1164 EXPECT
1165 Constant subroutine frèd redefined at - line 6.
1166 ########
1167 # op.c
1168 no warnings 'redefine' ;
1169 use utf8;
1170 use open qw( :utf8 :std );
1171 sub frèd () { 1 }
1172 sub frèd () { 2 }
1173 EXPECT
1174 Constant subroutine frèd redefined at - line 6.
1175 ########
1176 # op.c
1177 no warnings 'redefine' ;
1178 use utf8;
1179 use open qw( :utf8 :std );
1180 sub frèd () { 1 }
1181 *frèd = sub () { 2 };
1182 EXPECT
1183 Constant subroutine main::frèd redefined at - line 6.
1184 ########
1185 # op.c
1186 use warnings 'redefine' ;
1187 use utf8;
1188 use open qw( :utf8 :std );
1189 sub ᚠርƊ {}
1190 sub ᚠርƊ {}
1191 no warnings 'redefine' ;
1192 sub ᚠርƊ {}
1193 EXPECT
1194 Subroutine ᚠርƊ redefined at - line 6.
1195 ########
1196 # op.c
1197 use warnings 'redefine' ;
1198 use utf8;
1199 use open qw( :utf8 :std );
1200 sub ᚠርƊ () { 1 }
1201 sub ᚠርƊ () { 1 }
1202 no warnings 'redefine' ;
1203 sub ᚠርƊ () { 1 }
1204 EXPECT
1205 Constant subroutine ᚠርƊ redefined at - line 6.
1206 ########
1207 # op.c
1208 no warnings 'redefine' ;
1209 use utf8;
1210 use open qw( :utf8 :std );
1211 sub ᚠርƊ () { 1 }
1212 sub ᚠርƊ () { 2 }
1213 EXPECT
1214 Constant subroutine ᚠርƊ redefined at - line 6.
1215 ########
1216 # op.c
1217 no warnings 'redefine' ;
1218 use utf8;
1219 use open qw( :utf8 :std );
1220 sub ᚠርƊ () { 1 }
1221 *ᚠርƊ = sub () { 2 };
1222 EXPECT
1223 Constant subroutine main::ᚠርƊ redefined at - line 6.
1224 ########