xref: /openbsd/gnu/usr.bin/perl/t/lib/warnings/op (revision 76d0caae)
1  op.c		AOK
2
3     Found = in conditional, should be ==
4	1 if $a = 1 ;
5
6     Scalar value %.*s better written as $%.*s"
7	@a[3] = 2;
8	@a{3} = 2;
9
10     Useless use of time in void context
11     Useless use of a variable in void context
12     Useless use of a constant in void context
13	time ;
14	$a ;
15	"abc"
16
17     Useless use of sort in scalar context
18	my $x = sort (2,1,3);
19
20     Applying %s to %s will act on scalar(%s)
21	my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
22	@a =~ /abc/ ;
23	@a =~ s/a/b/ ;
24	@a =~ tr/a/b/ ;
25	@$b =~ /abc/ ;
26	@$b =~ s/a/b/ ;
27	@$b =~ tr/a/b/ ;
28	%a =~ /abc/ ;
29	%a =~ s/a/b/ ;
30	%a =~ tr/a/b/ ;
31	%$c =~ /abc/ ;
32	%$c =~ s/a/b/ ;
33	%$c =~ tr/a/b/ ;
34
35
36     Parentheses missing around "my" list at -e line 1.
37       my $a, $b = (1,2);
38
39     Parentheses missing around "local" list at -e line 1.
40       local $a, $b = (1,2);
41
42     Bareword found in conditional at -e line 1.
43       use warnings 'bareword'; my $x = print(ABC || 1);
44
45     Value of %s may be \"0\"; use \"defined\"
46	$x = 1 if $x = <FH> ;
47	$x = 1 while $x = <FH> ;
48
49     Subroutine fred redefined at -e line 1.
50       sub fred{1;} sub fred{1;}
51
52     Constant subroutine %s redefined
53        sub fred() {1;} sub fred() {1;}
54
55     Format FRED redefined at /tmp/x line 5.
56       format FRED =
57       .
58       format FRED =
59       .
60
61     Statement unlikely to be reached
62     	(Maybe you meant system() when you said exec()?
63 	exec "true" ; my $a
64
65     Can't use defined(@array) (Maybe you should just omit the defined()?)
66	my @a ; defined @a ;
67	defined (@a = (1,2,3)) ;
68
69     Can't use defined(%hash) (Maybe you should just omit the defined()?)
70	my %h ; defined %h ;
71
72     "my %s" used in sort comparison
73
74     $[ used in comparison (did you mean $] ?)
75
76     length() used on @array (did you mean "scalar(@array)"?)
77     length() used on %hash (did you mean "scalar(keys %hash)"?)
78
79     /---/ should probably be written as "---"
80        join(/---/, @foo);
81
82    %s() called too early to check prototype		[Perl_peep]
83        fred() ; sub fred ($$) {}
84
85
86    Package '%s' not found (did you use the incorrect case?)
87
88    Use of /g modifier is meaningless in split
89
90    Possible precedence problem on bitwise %c operator	[Perl_ck_bitop]
91
92    Mandatory Warnings
93    ------------------
94    Prototype mismatch:		[cv_ckproto]
95        sub fred() ;
96        sub fred($) {}
97
98    oops: oopsAV		[oopsAV]	TODO
99    oops: oopsHV		[oopsHV]	TODO
100
101__END__
102# op.c
103use warnings 'syntax' ;
1041 if $a = 1 ;
1051 if $a
106  = 1 ;
107no warnings 'syntax' ;
1081 if $a = 1 ;
1091 if $a
110  = 1 ;
111EXPECT
112Found = in conditional, should be == at - line 3.
113Found = in conditional, should be == at - line 4.
114########
115# op.c
116use warnings 'syntax' ;
117use constant foo => 1;
1181 if $a = foo ;
119no warnings 'syntax' ;
1201 if $a = foo ;
121EXPECT
122########
123# op.c
124# NAME unless with assignment as condition
125use warnings 'syntax';
1261 unless $a = 1;
127unless ($a = 1) {
128    1;
129}
130EXPECT
131Found = in conditional, should be == at - line 3.
132Found = in conditional, should be == at - line 4.
133########
134# op.c
135# NAME while with assignment as condition
136use warnings 'syntax';
1371 while $a = 0;
138while ($a = 0) {
139    1;
140}
141EXPECT
142Found = in conditional, should be == at - line 3.
143Found = in conditional, should be == at - line 4.
144########
145# op.c
146# NAME until with assignment as condition
147use warnings 'syntax';
1481 until $a = 1;
149until ($a = 1) {
150    1;
151}
152EXPECT
153Found = in conditional, should be == at - line 3.
154Found = in conditional, should be == at - line 4.
155########
156# op.c
157use warnings 'syntax' ;
158@a[3];
159@a{3};
160@a["]"];
161@a{"]"};
162@a["}"];
163@a{"}"};
164@a{$_};
165@a{--$_};
166@a[$_];
167@a[--$_];
168delete @a[$x];
169delete @a{$x};
170no warnings 'syntax' ;
171@a[3];
172@a{3};
173delete @a[$x];
174delete @a{$x};
175EXPECT
176Scalar value @a[3] better written as $a[3] at - line 3.
177Scalar value @a{3} better written as $a{3} at - line 4.
178Scalar value @a["]"] better written as $a["]"] at - line 5.
179Scalar value @a{"]"} better written as $a{"]"} at - line 6.
180Scalar value @a["}"] better written as $a["}"] at - line 7.
181Scalar value @a{"}"} better written as $a{"}"} at - line 8.
182Scalar value @a{...} better written as $a{...} at - line 9.
183Scalar value @a{...} better written as $a{...} at - line 10.
184Scalar value @a[...] better written as $a[...] at - line 11.
185Scalar value @a[...] better written as $a[...] at - line 12.
186Scalar value @a[...] better written as $a[...] at - line 13.
187Scalar value @a{...} better written as $a{...} at - line 14.
188########
189# op.c
190# [perl #132645]
191use warnings 'syntax';
192@inf[3];
193EXPECT
194Scalar value @inf[3] better written as $inf[3] at - line 4.
195########
196# op.c
197use utf8;
198use open qw( :utf8 :std );
199use warnings 'syntax' ;
200@à[3];
201@à{3};
202no warnings 'syntax' ;
203@à[3];
204@à{3};
205EXPECT
206Scalar value @à[3] better written as $à[3] at - line 5.
207Scalar value @à{3} better written as $à{3} at - line 6.
208########
209# op.c
210use utf8;
211use open qw( :utf8 :std );
212use warnings 'syntax' ;
213@ぁ[3];
214@ぁ{3};
215no warnings 'syntax' ;
216@ぁ[3];
217@ぁ{3};
218EXPECT
219Scalar value @ぁ[3] better written as $ぁ[3] at - line 5.
220Scalar value @ぁ{3} better written as $ぁ{3} at - line 6.
221########
222# op.c
223# "Scalar value better written as" false positives
224# [perl #28380] and [perl #114024]
225use warnings 'syntax';
226
227# hashes
228@h{qw"a b c"} = 1..3;
229@h{qw'a b c'} = 1..3;
230@h{qw$a b c$} = 1..3;
231@h{qw-a b c-} = 1..3;
232@h{qw#a b c#} = 1..3;
233@h{ qw#a b c#} = 1..3;
234@h{	qw#a b c#} = 1..3; # tab before qw
235@h{qw "a"};
236@h{ qw "a"};
237@h{	qw "a"};
238sub foo() { qw/abc def ghi/ }
239@X{+foo} = ( 1 .. 3 );
240$_ = "abc"; @X{split ""} = ( 1 .. 3 );
241my @s = @f{"}", "a"};
242my @s = @f{"]", "a"};
243@a{$],0};
244@_{0} = /(.*)/;
245@h{m "$re"};
246@h{qx ""} if 0;
247@h{glob ""};
248@h{readline ""};
249@h{m ""};
250use constant phoo => 1..3;
251@h{+phoo}; # rv2av
252@h{sort foo};
253@h{reverse foo};
254@h{caller 0};
255@h{lstat ""};
256@h{stat ""};
257@h{readdir ""};
258@h{system ""} if 0;
259@h{+times} if 0;
260@h{localtime 0};
261@h{gmtime 0};
262@h{eval ""};
263
264# arrays
265@h[qw"a b c"] = 1..3;
266@h[qw'a b c'] = 1..3;
267@h[qw$a b c$] = 1..3;
268@h[qw-a b c-] = 1..3;
269@h[qw#a b c#] = 1..3;
270@h[ qw#a b c#] = 1..3;
271@h[	qw#a b c#] = 1..3; # tab before qw
272@h[qw "a"];
273@h[ qw "a"];
274@h[	qw "a"];
275sub foo() { qw/abc def ghi/ }
276@X[+foo] = ( 1 .. 3 );
277$_ = "abc"; @X[split ""] = ( 1 .. 3 );
278my @s = @f["}", "a"];
279my @s = @f["]", "a"];
280@a[$],0];
281@_[0] = /(.*)/;
282@h[m "$re"];
283@h[qx ""] if 0;
284@h[glob ""];
285@h[readline ""];
286@h[m ""];
287use constant phoo => 1..3;
288@h[+phoo]; # rv2av
289@h[sort foo];
290@h[reverse foo];
291@h[caller 0];
292@h[lstat ""];
293@h[stat ""];
294@h[readdir ""];
295@h[system ""] if 0;
296@h[+times] if 0;
297@h[localtime 0];
298@h[gmtime 0];
299@h[eval ""];
300EXPECT
301########
302# op.c
303# "Scalar value better written as" should not trigger for syntax errors
304use warnings 'syntax';
305@a[]
306EXPECT
307syntax error at - line 4, near "[]"
308Execution of - aborted due to compilation errors.
309########
310# op.c
311my %foo;
312%main::foo->{"bar"};
313EXPECT
314OPTION fatal
315Can't use a hash as a reference at - line 3.
316########
317# op.c
318my %foo;
319%foo->{"bar"};
320EXPECT
321OPTION fatal
322Can't use a hash as a reference at - line 3.
323########
324# op.c
325my @foo;
326@main::foo->[23];
327EXPECT
328OPTION fatal
329Can't use an array as a reference at - line 3.
330########
331# op.c
332my @foo;
333@foo->[23];
334EXPECT
335OPTION fatal
336Can't use an array as a reference at - line 3.
337########
338# op.c
339my %foo;
340$main::foo = {}; %$main::foo->{"bar"};
341EXPECT
342OPTION fatal
343Can't use a hash as a reference at - line 3.
344########
345# op.c
346my %foo;
347$foo = {}; %$foo->{"bar"};
348EXPECT
349OPTION fatal
350Can't use a hash as a reference at - line 3.
351########
352# op.c
353my @foo;
354$main::foo = []; @$main::foo->[34];
355EXPECT
356OPTION fatal
357Can't use an array as a reference at - line 3.
358########
359# op.c
360my @foo;
361$foo = []; @$foo->[34];
362EXPECT
363OPTION fatal
364Can't use an array as a reference at - line 3.
365########
366# op.c
367use warnings 'void' ; no warnings 'experimental::smartmatch'; close STDIN ;
368#line 2
3691 x 3 ;			# OP_REPEAT (folded)
370(1) x 3 ;		# OP_REPEAT
371			# OP_GVSV
372wantarray ; 		# OP_WANTARRAY
373			# OP_GV
374			# OP_PADSV
375			# OP_PADAV
376			# OP_PADHV
377			# OP_PADANY
378			# OP_AV2ARYLEN
379ref ;			# OP_REF
380\(@a) ;			# OP_REFGEN
381\$a ;			# OP_SREFGEN
382defined $a ;		# OP_DEFINED
383hex $a ;		# OP_HEX
384oct $a ;		# OP_OCT
385length $a ;		# OP_LENGTH
386substr $a,1 ;		# OP_SUBSTR
387vec $a,1,2 ;		# OP_VEC
388index $a,1,2 ;		# OP_INDEX
389rindex $a,1,2 ;		# OP_RINDEX
390sprintf $a ;		# OP_SPRINTF
391$a[0] ;			# OP_AELEM
392			# OP_AELEMFAST
393@a[0] ;			# OP_ASLICE
394#values %a ;		# OP_VALUES
395#keys %a ;		# OP_KEYS
396$a{0} ;			# OP_HELEM
397@a{0} ;			# OP_HSLICE
398unpack "a", "a" ;	# OP_UNPACK
399pack $a,"" ;		# OP_PACK
400join "", @_ ;		# OP_JOIN
401(@a)[0,1] ;		# OP_LSLICE
402			# OP_ANONLIST
403			# OP_ANONHASH
404sort(1,2) ;		# OP_SORT
405reverse(1,2) ;		# OP_REVERSE
406			# OP_RANGE
407			# OP_FLIP
408(1 ..2) ;		# OP_FLOP
409caller ;		# OP_CALLER
410fileno STDIN ;		# OP_FILENO
411eof STDIN ;		# OP_EOF
412tell STDIN ;		# OP_TELL
413readlink 1;		# OP_READLINK
414time ;			# OP_TIME
415localtime ;		# OP_LOCALTIME
416gmtime ;		# OP_GMTIME
417eval { getgrnam 1 };	# OP_GGRNAM
418eval { getgrgid 1 };	# OP_GGRGID
419eval { getpwnam 1 };	# OP_GPWNAM
420eval { getpwuid 1 };	# OP_GPWUID
421prototype "foo";	# OP_PROTOTYPE
422$a ~~ $b;		# OP_SMARTMATCH
423$a <=> $b;		# OP_NCMP
424"dsatrewq";
425"diatrewq";
426"igatrewq";
427use 5.015;
428__SUB__	;		# OP_RUNCV
429[];			# OP_ANONLIST
430grep /42/, (1,2);	# OP_GREP. Not warned about (yet). Grep git logs for void_unusual to see why...
431EXPECT
432Useless use of a constant ("111") in void context at - line 2.
433Useless use of repeat (x) in void context at - line 3.
434Useless use of wantarray in void context at - line 5.
435Useless use of reference-type operator in void context at - line 12.
436Useless use of reference constructor in void context at - line 13.
437Useless use of single ref constructor in void context at - line 14.
438Useless use of defined operator in void context at - line 15.
439Useless use of hex in void context at - line 16.
440Useless use of oct in void context at - line 17.
441Useless use of length in void context at - line 18.
442Useless use of substr in void context at - line 19.
443Useless use of vec in void context at - line 20.
444Useless use of index in void context at - line 21.
445Useless use of rindex in void context at - line 22.
446Useless use of sprintf in void context at - line 23.
447Useless use of array element in void context at - line 24.
448Useless use of array slice in void context at - line 26.
449Useless use of hash element in void context at - line 29.
450Useless use of hash slice in void context at - line 30.
451Useless use of unpack in void context at - line 31.
452Useless use of pack in void context at - line 32.
453Useless use of join or string in void context at - line 33.
454Useless use of list slice in void context at - line 34.
455Useless use of sort in void context at - line 37.
456Useless use of reverse in void context at - line 38.
457Useless use of range (or flop) in void context at - line 41.
458Useless use of caller in void context at - line 42.
459Useless use of fileno in void context at - line 43.
460Useless use of eof in void context at - line 44.
461Useless use of tell in void context at - line 45.
462Useless use of readlink in void context at - line 46.
463Useless use of time in void context at - line 47.
464Useless use of localtime in void context at - line 48.
465Useless use of gmtime in void context at - line 49.
466Useless use of getgrnam in void context at - line 50.
467Useless use of getgrgid in void context at - line 51.
468Useless use of getpwnam in void context at - line 52.
469Useless use of getpwuid in void context at - line 53.
470Useless use of subroutine prototype in void context at - line 54.
471Useless use of smart match in void context at - line 55.
472Useless use of numeric comparison (<=>) in void context at - line 56.
473Useless use of a constant ("dsatrewq") in void context at - line 57.
474Useless use of a constant ("diatrewq") in void context at - line 58.
475Useless use of a constant ("igatrewq") in void context at - line 59.
476Useless use of __SUB__ in void context at - line 61.
477Useless use of anonymous array ([]) in void context at - line 62.
478########
479# op.c
480use warnings 'void' ; close STDIN ;
481my $x = sort (2,1,3);
482no warnings 'void' ;
483$x = sort (2,1,3);
484EXPECT
485Useless use of sort in scalar context at - line 3.
486########
487# op.c
488no warnings 'void' ; close STDIN ;
4891 x 3 ;			# OP_REPEAT
490			# OP_GVSV
491wantarray ; 		# OP_WANTARRAY
492			# OP_GV
493			# OP_PADSV
494			# OP_PADAV
495			# OP_PADHV
496			# OP_PADANY
497			# OP_AV2ARYLEN
498ref ;			# OP_REF
499\@a ;			# OP_REFGEN
500\$a ;			# OP_SREFGEN
501defined $a ;		# OP_DEFINED
502hex $a ;		# OP_HEX
503oct $a ;		# OP_OCT
504length $a ;		# OP_LENGTH
505substr $a,1 ;		# OP_SUBSTR
506vec $a,1,2 ;		# OP_VEC
507index $a,1,2 ;		# OP_INDEX
508rindex $a,1,2 ;		# OP_RINDEX
509sprintf $a ;		# OP_SPRINTF
510$a[0] ;			# OP_AELEM
511			# OP_AELEMFAST
512@a[0] ;			# OP_ASLICE
513#values %a ;		# OP_VALUES
514#keys %a ;		# OP_KEYS
515$a{0} ;			# OP_HELEM
516@a{0} ;			# OP_HSLICE
517unpack "a", "a" ;	# OP_UNPACK
518pack $a,"" ;		# OP_PACK
519join "" ;		# OP_JOIN
520(@a)[0,1] ;		# OP_LSLICE
521			# OP_ANONLIST
522			# OP_ANONHASH
523sort(1,2) ;		# OP_SORT
524reverse(1,2) ;		# OP_REVERSE
525			# OP_RANGE
526			# OP_FLIP
527(1 ..2) ;		# OP_FLOP
528caller ;		# OP_CALLER
529fileno STDIN ;		# OP_FILENO
530eof STDIN ;		# OP_EOF
531tell STDIN ;		# OP_TELL
532readlink 1;		# OP_READLINK
533time ;			# OP_TIME
534localtime ;		# OP_LOCALTIME
535gmtime ;		# OP_GMTIME
536eval { getgrnam 1 };	# OP_GGRNAM
537eval { getgrgid 1 };	# OP_GGRGID
538eval { getpwnam 1 };	# OP_GPWNAM
539eval { getpwuid 1 };	# OP_GPWUID
540prototype "foo";	# OP_PROTOTYPE
541EXPECT
542########
543# op.c
544use warnings 'void' ;
545for (@{[0]}) { "$_" }		# check warning isn't duplicated
546no warnings 'void' ;
547for (@{[0]}) { "$_" }		# check warning isn't duplicated
548EXPECT
549Useless use of string in void context at - line 3.
550########
551# op.c
552use warnings 'void' ;
553use Config ;
554BEGIN {
555    if ( ! $Config{d_telldir}) {
556        print <<EOM ;
557SKIPPED
558# telldir not present
559EOM
560        exit
561    }
562}
563telldir 1 ;		# OP_TELLDIR
564no warnings 'void' ;
565telldir 1 ;		# OP_TELLDIR
566EXPECT
567Useless use of telldir in void context at - line 13.
568########
569# op.c
570use warnings 'void' ;
571use Config ;
572BEGIN {
573    if ( ! $Config{d_getppid}) {
574        print <<EOM ;
575SKIPPED
576# getppid not present
577EOM
578        exit
579    }
580}
581getppid ;		# OP_GETPPID
582no warnings 'void' ;
583getppid ;		# OP_GETPPID
584EXPECT
585Useless use of getppid in void context at - line 13.
586########
587# op.c
588use warnings 'void' ;
589use Config ;
590BEGIN {
591    if ( ! $Config{d_getpgrp}) {
592        print <<EOM ;
593SKIPPED
594# getpgrp not present
595EOM
596        exit
597    }
598}
599getpgrp ;		# OP_GETPGRP
600no warnings 'void' ;
601getpgrp ;		# OP_GETPGRP
602EXPECT
603Useless use of getpgrp in void context at - line 13.
604########
605# op.c
606use warnings 'void' ;
607use Config ;
608BEGIN {
609    if ( ! $Config{d_times}) {
610        print <<EOM ;
611SKIPPED
612# times not present
613EOM
614        exit
615    }
616}
617times ;			# OP_TMS
618no warnings 'void' ;
619times ;			# OP_TMS
620EXPECT
621Useless use of times in void context at - line 13.
622########
623# op.c
624use warnings 'void' ;
625use Config ;
626BEGIN {
627    if ( ! $Config{d_getprior} or $^O eq 'os2') { # Locks before fixpak22
628        print <<EOM ;
629SKIPPED
630# getpriority not present
631EOM
632        exit
633    }
634}
635getpriority 1,2;	# OP_GETPRIORITY
636no warnings 'void' ;
637getpriority 1,2;	# OP_GETPRIORITY
638EXPECT
639Useless use of getpriority in void context at - line 13.
640########
641# op.c
642use warnings 'void' ;
643use Config ;
644BEGIN {
645    if ( ! $Config{d_getlogin}) {
646        print <<EOM ;
647SKIPPED
648# getlogin not present
649EOM
650        exit
651    }
652}
653getlogin ;			# OP_GETLOGIN
654no warnings 'void' ;
655getlogin ;			# OP_GETLOGIN
656EXPECT
657Useless use of getlogin in void context at - line 13.
658########
659# op.c
660use warnings 'void' ;
661use Config ; BEGIN {
662if ( ! $Config{d_socket}) {
663    print <<EOM ;
664SKIPPED
665# getsockname not present
666# getpeername not present
667# gethostbyname not present
668# gethostbyaddr not present
669# gethostent not present
670# getnetbyname not present
671# getnetbyaddr not present
672# getnetent not present
673# getprotobyname not present
674# getprotobynumber not present
675# getprotoent not present
676# getservbyname not present
677# getservbyport not present
678# getservent not present
679EOM
680    exit
681} }
682getsockname STDIN ;	# OP_GETSOCKNAME
683getpeername STDIN ;	# OP_GETPEERNAME
684gethostbyname 1 ;	# OP_GHBYNAME
685gethostbyaddr 1,2;	# OP_GHBYADDR
686gethostent ;		# OP_GHOSTENT
687getnetbyname 1 ;	# OP_GNBYNAME
688getnetbyaddr 1,2 ;	# OP_GNBYADDR
689getnetent ;		# OP_GNETENT
690getprotobyname 1;	# OP_GPBYNAME
691getprotobynumber 1;	# OP_GPBYNUMBER
692getprotoent ;		# OP_GPROTOENT
693getservbyname 1,2;	# OP_GSBYNAME
694getservbyport 1,2;	# OP_GSBYPORT
695getservent ;		# OP_GSERVENT
696
697no warnings 'void' ;
698getsockname STDIN ;	# OP_GETSOCKNAME
699getpeername STDIN ;	# OP_GETPEERNAME
700gethostbyname 1 ;	# OP_GHBYNAME
701gethostbyaddr 1,2;	# OP_GHBYADDR
702gethostent ;		# OP_GHOSTENT
703getnetbyname 1 ;	# OP_GNBYNAME
704getnetbyaddr 1,2 ;	# OP_GNBYADDR
705getnetent ;		# OP_GNETENT
706getprotobyname 1;	# OP_GPBYNAME
707getprotobynumber 1;	# OP_GPBYNUMBER
708getprotoent ;		# OP_GPROTOENT
709getservbyname 1,2;	# OP_GSBYNAME
710getservbyport 1,2;	# OP_GSBYPORT
711getservent ;		# OP_GSERVENT
712INIT {
713   # some functions may not be there, so we exit without running
714   exit;
715}
716EXPECT
717Useless use of getsockname in void context at - line 24.
718Useless use of getpeername in void context at - line 25.
719Useless use of gethostbyname in void context at - line 26.
720Useless use of gethostbyaddr in void context at - line 27.
721Useless use of gethostent in void context at - line 28.
722Useless use of getnetbyname in void context at - line 29.
723Useless use of getnetbyaddr in void context at - line 30.
724Useless use of getnetent in void context at - line 31.
725Useless use of getprotobyname in void context at - line 32.
726Useless use of getprotobynumber in void context at - line 33.
727Useless use of getprotoent in void context at - line 34.
728Useless use of getservbyname in void context at - line 35.
729Useless use of getservbyport in void context at - line 36.
730Useless use of getservent in void context at - line 37.
731########
732# op.c
733use warnings 'void' ;
734*a ; # OP_RV2GV
735$a ; # OP_RV2SV
736@a ; # OP_RV2AV
737%a ; # OP_RV2HV
738no warnings 'void' ;
739*a ; # OP_RV2GV
740$a ; # OP_RV2SV
741@a ; # OP_RV2AV
742%a ; # OP_RV2HV
743EXPECT
744Useless use of a variable in void context at - line 3.
745Useless use of a variable in void context at - line 4.
746Useless use of a variable in void context at - line 5.
747Useless use of a variable in void context at - line 6.
748########
749# op.c
750use warnings 'void' ;
751"abc"; # OP_CONST
7527 ; # OP_CONST
753"x" . "y"; # optimized to OP_CONST
7542 + 2; # optimized to OP_CONST
755use constant U => undef;
756U;
757qq/"	\n/;
7585 || print "bad\n";	# test OPpCONST_SHORTCIRCUIT
759print "boo\n" if U;	# test OPpCONST_SHORTCIRCUIT
760if($foo){}elsif(""){}	# test OPpCONST_SHORTCIRCUIT
761no warnings 'void' ;
762"abc"; # OP_CONST
7637 ; # OP_CONST
764"x" . "y"; # optimized to OP_CONST
7652 + 2; # optimized to OP_CONST
766EXPECT
767Useless use of a constant ("abc") in void context at - line 3.
768Useless use of a constant (7) in void context at - line 4.
769Useless use of a constant ("xy") in void context at - line 5.
770Useless use of a constant (4) in void context at - line 6.
771Useless use of a constant (undef) in void context at - line 8.
772Useless use of a constant ("\"\t\n") in void context at - line 9.
773########
774# op.c
775BEGIN {
776    if (ord('A') == 193) {
777        print "SKIPPED\n# Result varies depending on EBCDIC code page";
778        exit 0;
779    }
780}
781use utf8;
782use open qw( :utf8 :std );
783use warnings 'void' ;
784"àḆc"; # OP_CONST
785EXPECT
786Useless use of a constant ("\340\x{1e06}c") in void context at - line 11.
787########
788# op.c
789use utf8;
790use open qw( :utf8 :std );
791use warnings 'void' ;
792"Ẋ" . "ƴ"; # optimized to OP_CONST
793FOO;     # Bareword optimized to OP_CONST
794use constant ů => undef;
795ů;
7965 || print "bad\n";	# test OPpCONST_SHORTCIRCUIT
797print "boo\n" if ů;	# test OPpCONST_SHORTCIRCUIT
798no warnings 'void' ;
799"àḆc"; # OP_CONST
800"Ẋ" . "ƴ"; # optimized to OP_CONST
801EXPECT
802Useless use of a constant ("\x{1e8a}\x{1b4}") in void context at - line 5.
803Useless use of a constant ("\x{ff26}\x{ff2f}\x{ff2f}") in void context at - line 6.
804Useless use of a constant (undef) in void context at - line 8.
805########
806# op.c
807#
808use warnings 'misc' ; use utf8;
809my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;my $d = 'test';
810@a =~ /abc/ ;
811@a2 =~ s/a/b/ ;
812@a3 =~ tr/a/b/ ;
813@$b =~ /abc/ ;
814@$b =~ s/a/b/ ;
815@$b =~ tr/a/b/ ;
816%a =~ /abc/ ;
817%a2 =~ s/a/b/ ;
818%a3 =~ tr/a/b/ ;
819%$c =~ /abc/ ;
820%$c =~ s/a/b/ ;
821%$c =~ tr/a/b/ ;
822$d =~ tr/a/b/d ;
823$d2 =~ tr/a/bc/;
824$d3 =~ tr//b/c;
825$d =~ tr/α/β/d ;
826$d2 =~ tr/α/βγ/;
827{
828no warnings 'misc' ;
829my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; my $d = 'test';
830@a =~ /abc/ ;
831@a =~ s/a/b/ ;
832@a =~ tr/a/b/ ;
833@$b =~ /abc/ ;
834@$b =~ s/a/b/ ;
835@$b =~ tr/a/b/ ;
836%a =~ /abc/ ;
837%a =~ s/a/b/ ;
838%a =~ tr/a/b/ ;
839%$c =~ /abc/ ;
840%$c =~ s/a/b/ ;
841%$c =~ tr/a/b/ ;
842$d =~ tr/a/b/d ;
843$d =~ tr/a/bc/ ;
844$d =~ tr//b/c;
845}
846EXPECT
847Applying pattern match (m//) to @a will act on scalar(@a) at - line 5.
848Applying substitution (s///) to @a2 will act on scalar(@a2) at - line 6.
849Applying transliteration (tr///) to @a3 will act on scalar(@a3) at - line 7.
850Applying pattern match (m//) to @array will act on scalar(@array) at - line 8.
851Applying substitution (s///) to @array will act on scalar(@array) at - line 9.
852Applying transliteration (tr///) to @array will act on scalar(@array) at - line 10.
853Applying pattern match (m//) to %a will act on scalar(%a) at - line 11.
854Applying substitution (s///) to %a2 will act on scalar(%a2) at - line 12.
855Applying transliteration (tr///) to %a3 will act on scalar(%a3) at - line 13.
856Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 14.
857Applying substitution (s///) to %hash will act on scalar(%hash) at - line 15.
858Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 16.
859Useless use of /d modifier in transliteration operator at - line 17.
860Replacement list is longer than search list at - line 18.
861Useless use of /d modifier in transliteration operator at - line 20.
862Replacement list is longer than search list at - line 21.
863Can't modify array dereference in substitution (s///) at - line 6, near "s/a/b/ ;"
864BEGIN not safe after errors--compilation aborted at - line 23.
865########
866# op.c
867use warnings 'parenthesis' ;
868my $a, $b = (1,2);
869my @foo,%bar,	$quux; # there's a TAB here
870my $x, $y or print;
871my $p, *q;
872no warnings 'parenthesis' ;
873my $c, $d = (1,2);
874EXPECT
875Parentheses missing around "my" list at - line 3.
876Parentheses missing around "my" list at - line 4.
877########
878# op.c
879use warnings 'parenthesis' ;
880our $a, $b = (1,2);
881our $p, *q;
882no warnings 'parenthesis' ;
883our $c, $d = (1,2);
884EXPECT
885Parentheses missing around "our" list at - line 3.
886########
887# op.c
888use warnings 'parenthesis' ;
889local $a, $b = (1,2);
890local *f, *g;
891local $p, *q;
892no warnings 'parenthesis' ;
893local $c, $d = (1,2);
894EXPECT
895Parentheses missing around "local" list at - line 3.
896Parentheses missing around "local" list at - line 4.
897Parentheses missing around "local" list at - line 5.
898########
899# op.c
900use warnings 'bareword' ;
901print (ABC || 1) ;
902no warnings 'bareword' ;
903print (ABC || 1) ;
904EXPECT
905Bareword found in conditional at - line 3.
906########
907--FILE-- abc
908
909--FILE--
910# op.c
911use warnings 'misc' ;
912open FH, "<abc" ;
913$x = 1 if $x = <FH> ;
914$x = 1 if $x
915     = <FH> ;
916no warnings 'misc' ;
917$x = 1 if $x = <FH> ;
918$x = 1 if $x
919     = <FH> ;
920EXPECT
921Value of <HANDLE> construct can be "0"; test with defined() at - line 4.
922Value of <HANDLE> construct can be "0"; test with defined() at - line 5.
923########
924# op.c
925use warnings 'misc' ;
926opendir FH, "." ;
927$x = 1 if $x = readdir FH ;
928$x = 1 if $x
929    = readdir FH ;
930no warnings 'misc' ;
931$x = 1 if $x = readdir FH ;
932$x = 1 if $x
933    = readdir FH ;
934closedir FH ;
935EXPECT
936Value of readdir() operator can be "0"; test with defined() at - line 4.
937Value of readdir() operator can be "0"; test with defined() at - line 5.
938########
939# op.c
940use warnings 'misc' ;
941$x = 1 if $x = <*> ;
942$x = 1 if $x
943    = <*> ;
944no warnings 'misc' ;
945$x = 1 if $x = <*> ;
946$x = 1 if $x
947    = <*> ;
948EXPECT
949Value of glob construct can be "0"; test with defined() at - line 3.
950Value of glob construct can be "0"; test with defined() at - line 4.
951########
952# op.c
953use warnings 'misc' ;
954%a = (1,2,3,4) ;
955$x = 1 if $x = each %a ;
956no warnings 'misc' ;
957$x = 1 if $x = each %a ;
958EXPECT
959Value of each() operator can be "0"; test with defined() at - line 4.
960########
961# op.c
962use warnings 'misc' ;
963$x = 1 while $x = <*> and 0 ;
964no warnings 'misc' ;
965$x = 1 while $x = <*> and 0 ;
966EXPECT
967Value of glob construct can be "0"; test with defined() at - line 3.
968########
969# op.c
970use warnings 'misc' ;
971opendir FH, "." ;
972$x = 1 while $x = readdir FH and 0 ;
973no warnings 'misc' ;
974$x = 1 while $x = readdir FH and 0 ;
975closedir FH ;
976EXPECT
977Value of readdir() operator can be "0"; test with defined() at - line 4.
978########
979# op.c
980use warnings 'misc';
981open FH, "<abc";
982($_ = <FH>) // ($_ = 1);
983opendir DH, ".";
984%a = (1,2,3,4) ;
985EXPECT
986########
987# op.c
988use warnings 'redefine' ;
989sub fred {}
990sub fred {}
991sub fred { # warning should be for this line
992}
993no warnings 'redefine' ;
994sub fred {}
995sub fred {
996}
997EXPECT
998Subroutine fred redefined at - line 4.
999Subroutine fred redefined at - line 5.
1000########
1001# op.c
1002use warnings 'redefine' ;
1003sub fred () { 1 }
1004sub fred () { 1 }
1005no warnings 'redefine' ;
1006sub fred () { 1 }
1007EXPECT
1008Constant subroutine fred redefined at - line 4.
1009########
1010# op.c
1011sub fred () { 1 }
1012sub fred () { 2 }
1013EXPECT
1014Constant subroutine fred redefined at - line 3.
1015########
1016# op.c
1017sub fred () { 1 }
1018*fred = sub () { 2 };
1019EXPECT
1020Constant subroutine main::fred redefined at - line 3.
1021########
1022# op.c
1023use feature "lexical_subs", "state";
1024my sub fred () { 1 }
1025sub fred { 2 };
1026my sub george { 1 }
1027sub george () { 2 } # should *not* produce redef warnings by default
1028state sub phred () { 1 }
1029sub phred { 2 };
1030state sub jorge { 1 }
1031sub jorge () { 2 } # should *not* produce redef warnings by default
1032EXPECT
1033Prototype mismatch: sub fred () vs none at - line 4.
1034Constant subroutine fred redefined at - line 4.
1035Prototype mismatch: sub george: none vs () at - line 6.
1036Prototype mismatch: sub phred () vs none at - line 8.
1037Constant subroutine phred redefined at - line 8.
1038Prototype mismatch: sub jorge: none vs () at - line 10.
1039########
1040# op.c
1041no warnings 'redefine' ;
1042sub fred () { 1 }
1043sub fred () { 2 }
1044EXPECT
1045########
1046# op.c
1047no warnings 'redefine' ;
1048sub fred () { 1 }
1049*fred = sub () { 2 };
1050EXPECT
1051########
1052# op.c
1053use warnings 'redefine' ;
1054format FRED =
1055.
1056format FRED =
1057.
1058no warnings 'redefine' ;
1059format FRED =
1060.
1061EXPECT
1062Format FRED redefined at - line 5.
1063########
1064# op.c
1065use warnings 'exec' ;
1066exec "$^X -e 1" ;
1067my $a
1068EXPECT
1069Statement unlikely to be reached at - line 4.
1070	(Maybe you meant system() when you said exec()?)
1071########
1072# op.c, no warning if exec isn't a statement.
1073use warnings 'exec' ;
1074$a || exec "$^X -e 1" ;
1075my $a
1076EXPECT
1077########
1078# op.c
1079defined(@a);
1080EXPECT
1081OPTION fatal
1082Can't use 'defined(@array)' (Maybe you should just omit the defined()?) at - line 2.
1083########
1084# op.c
1085my @a; defined(@a);
1086EXPECT
1087OPTION fatal
1088Can't use 'defined(@array)' (Maybe you should just omit the defined()?) at - line 2.
1089########
1090# op.c
1091defined(@a = (1,2,3));
1092EXPECT
1093########
1094# op.c
1095defined(%h);
1096EXPECT
1097OPTION fatal
1098Can't use 'defined(%hash)' (Maybe you should just omit the defined()?) at - line 2.
1099########
1100# op.c
1101my %h; defined(%h);
1102EXPECT
1103OPTION fatal
1104Can't use 'defined(%hash)' (Maybe you should just omit the defined()?) at - line 2.
1105########
1106# op.c
1107no warnings 'exec' ;
1108exec "$^X -e 1" ;
1109my $a
1110EXPECT
1111
1112########
1113# op.c
1114sub fred();
1115sub fred($) {}
1116use constant foo=>bar; sub foo(@);
1117use constant bav=>bar; sub bav(); # no warning
1118sub btu; sub btu();
1119EXPECT
1120Prototype mismatch: sub main::fred () vs ($) at - line 3.
1121Prototype mismatch: sub foo () vs (@) at - line 4.
1122Prototype mismatch: sub btu: none vs () at - line 6.
1123########
1124# op.c
1125use utf8;
1126use open qw( :utf8 :std );
1127sub frèd();
1128sub frèd($) {}
1129EXPECT
1130Prototype mismatch: sub main::frèd () vs ($) at - line 5.
1131########
1132# op.c
1133use utf8;
1134use open qw( :utf8 :std );
1135use warnings;
1136BEGIN { $::{"foo"} = "\x{30cb}" }
1137BEGIN { eval "sub foo {}"; }
1138EXPECT
1139Prototype mismatch: sub main::foo (ニ) vs none at (eval 1) line 1.
1140########
1141# op.c
1142$^W = 0 ;
1143sub fred() ;
1144sub fred($) {}
1145{
1146    no warnings 'prototype' ;
1147    sub Fred() ;
1148    sub Fred($) {}
1149    use warnings 'prototype' ;
1150    sub freD() ;
1151    sub freD($) {}
1152}
1153sub FRED() ;
1154sub FRED($) {}
1155EXPECT
1156Prototype mismatch: sub main::fred () vs ($) at - line 4.
1157Prototype mismatch: sub main::freD () vs ($) at - line 11.
1158Prototype mismatch: sub main::FRED () vs ($) at - line 14.
1159########
1160# op.c [S_simplify_sort]
1161# [perl #86136]
1162my @tests = split /^/, '
1163  sort {$a <=> $b} @a;
1164  sort {$a cmp $b} @a;
1165  { use integer; sort {$a <=> $b} @a}
1166  sort {$b <=> $a} @a;
1167  sort {$b cmp $a} @a;
1168  { use integer; sort {$b <=> $a} @a}
1169';
1170for my $pragma ('use warnings "syntax";', '') {
1171  for my $vars ('', 'my $a;', 'my $b;', 'my ($a,$b);') {
1172    for my $inner_stmt ('', 'print;', 'func();') {
1173      eval "#line " . ++$line . "01 -\n$pragma\n$vars"
1174          . join "", map s/sort \{\K/$inner_stmt/r, @tests;
1175      $@ and die;
1176    }
1177  }
1178}
1179sub func{}
1180use warnings 'syntax';
1181my $a;
1182# These used to be errors!
1183sort { ; } $a <=> $b;
1184sort { ; } $a, "<=>";
1185sort { ; } $a, $cmp;
1186sort $a, $b if $cmpany_name;
1187sort if $a + $cmp;
1188sort @t; $a + $cmp;
1189EXPECT
1190"my $a" used in sort comparison at - line 403.
1191"my $a" used in sort comparison at - line 404.
1192"my $a" used in sort comparison at - line 405.
1193"my $a" used in sort comparison at - line 406.
1194"my $a" used in sort comparison at - line 407.
1195"my $a" used in sort comparison at - line 408.
1196"my $a" used in sort comparison at - line 503.
1197"my $a" used in sort comparison at - line 504.
1198"my $a" used in sort comparison at - line 505.
1199"my $a" used in sort comparison at - line 506.
1200"my $a" used in sort comparison at - line 507.
1201"my $a" used in sort comparison at - line 508.
1202"my $a" used in sort comparison at - line 603.
1203"my $a" used in sort comparison at - line 604.
1204"my $a" used in sort comparison at - line 605.
1205"my $a" used in sort comparison at - line 606.
1206"my $a" used in sort comparison at - line 607.
1207"my $a" used in sort comparison at - line 608.
1208"my $b" used in sort comparison at - line 703.
1209"my $b" used in sort comparison at - line 704.
1210"my $b" used in sort comparison at - line 705.
1211"my $b" used in sort comparison at - line 706.
1212"my $b" used in sort comparison at - line 707.
1213"my $b" used in sort comparison at - line 708.
1214"my $b" used in sort comparison at - line 803.
1215"my $b" used in sort comparison at - line 804.
1216"my $b" used in sort comparison at - line 805.
1217"my $b" used in sort comparison at - line 806.
1218"my $b" used in sort comparison at - line 807.
1219"my $b" used in sort comparison at - line 808.
1220"my $b" used in sort comparison at - line 903.
1221"my $b" used in sort comparison at - line 904.
1222"my $b" used in sort comparison at - line 905.
1223"my $b" used in sort comparison at - line 906.
1224"my $b" used in sort comparison at - line 907.
1225"my $b" used in sort comparison at - line 908.
1226"my $a" used in sort comparison at - line 1003.
1227"my $b" used in sort comparison at - line 1003.
1228"my $a" used in sort comparison at - line 1004.
1229"my $b" used in sort comparison at - line 1004.
1230"my $a" used in sort comparison at - line 1005.
1231"my $b" used in sort comparison at - line 1005.
1232"my $b" used in sort comparison at - line 1006.
1233"my $a" used in sort comparison at - line 1006.
1234"my $b" used in sort comparison at - line 1007.
1235"my $a" used in sort comparison at - line 1007.
1236"my $b" used in sort comparison at - line 1008.
1237"my $a" used in sort comparison at - line 1008.
1238"my $a" used in sort comparison at - line 1103.
1239"my $b" used in sort comparison at - line 1103.
1240"my $a" used in sort comparison at - line 1104.
1241"my $b" used in sort comparison at - line 1104.
1242"my $a" used in sort comparison at - line 1105.
1243"my $b" used in sort comparison at - line 1105.
1244"my $b" used in sort comparison at - line 1106.
1245"my $a" used in sort comparison at - line 1106.
1246"my $b" used in sort comparison at - line 1107.
1247"my $a" used in sort comparison at - line 1107.
1248"my $b" used in sort comparison at - line 1108.
1249"my $a" used in sort comparison at - line 1108.
1250"my $a" used in sort comparison at - line 1203.
1251"my $b" used in sort comparison at - line 1203.
1252"my $a" used in sort comparison at - line 1204.
1253"my $b" used in sort comparison at - line 1204.
1254"my $a" used in sort comparison at - line 1205.
1255"my $b" used in sort comparison at - line 1205.
1256"my $b" used in sort comparison at - line 1206.
1257"my $a" used in sort comparison at - line 1206.
1258"my $b" used in sort comparison at - line 1207.
1259"my $a" used in sort comparison at - line 1207.
1260"my $b" used in sort comparison at - line 1208.
1261"my $a" used in sort comparison at - line 1208.
1262########
1263# op.c [S_simplify_sort]
1264use warnings 'syntax'; use 5.01;
1265state $a;
1266sort { $a <=> $b } ();
1267EXPECT
1268"state $a" used in sort comparison at - line 4.
1269########
1270# op.c [Perl_ck_cmp]
1271use warnings 'syntax' ;
1272no warnings 'deprecated';
1273@a = $[ < 5;
1274@a = $[ > 5;
1275@a = $[ <= 5;
1276@a = $[ >= 5;
1277@a = 42 < $[;
1278@a = 42 > $[;
1279@a = 42 <= $[;
1280@a = 42 >= $[;
1281use integer;
1282@a = $[ < 5;
1283@a = $[ > 5;
1284@a = $[ <= 5;
1285@a = $[ >= 5;
1286@a = 42 < $[;
1287@a = 42 > $[;
1288@a = 42 <= $[;
1289@a = 42 >= $[;
1290no integer;
1291@a = $[ < $5;
1292@a = $[ > $5;
1293@a = $[ <= $5;
1294@a = $[ >= $5;
1295@a = $42 < $[;
1296@a = $42 > $[;
1297@a = $42 <= $[;
1298@a = $42 >= $[;
1299use integer;
1300@a = $[ < $5;
1301@a = $[ > $5;
1302@a = $[ <= $5;
1303@a = $[ >= $5;
1304@a = $42 < $[;
1305@a = $42 > $[;
1306@a = $42 <= $[;
1307@a = $42 >= $[;
1308EXPECT
1309$[ used in numeric lt (<) (did you mean $] ?) at - line 4.
1310$[ used in numeric gt (>) (did you mean $] ?) at - line 5.
1311$[ used in numeric le (<=) (did you mean $] ?) at - line 6.
1312$[ used in numeric ge (>=) (did you mean $] ?) at - line 7.
1313$[ used in numeric lt (<) (did you mean $] ?) at - line 8.
1314$[ used in numeric gt (>) (did you mean $] ?) at - line 9.
1315$[ used in numeric le (<=) (did you mean $] ?) at - line 10.
1316$[ used in numeric ge (>=) (did you mean $] ?) at - line 11.
1317$[ used in numeric lt (<) (did you mean $] ?) at - line 13.
1318$[ used in numeric gt (>) (did you mean $] ?) at - line 14.
1319$[ used in numeric le (<=) (did you mean $] ?) at - line 15.
1320$[ used in numeric ge (>=) (did you mean $] ?) at - line 16.
1321$[ used in numeric lt (<) (did you mean $] ?) at - line 17.
1322$[ used in numeric gt (>) (did you mean $] ?) at - line 18.
1323$[ used in numeric le (<=) (did you mean $] ?) at - line 19.
1324$[ used in numeric ge (>=) (did you mean $] ?) at - line 20.
1325########
1326# op.c [Perl_ck_length]
1327use warnings 'syntax' ;
1328length(@a);
1329length(%b);
1330length(@$c);
1331length(%$d);
1332length($a);
1333length(my %h);
1334length(my @g);
1335EXPECT
1336length() used on @a (did you mean "scalar(@a)"?) at - line 3.
1337length() used on %b (did you mean "scalar(keys %b)"?) at - line 4.
1338length() used on @array (did you mean "scalar(@array)"?) at - line 5.
1339length() used on %hash (did you mean "scalar(keys %hash)"?) at - line 6.
1340length() used on %h (did you mean "scalar(keys %h)"?) at - line 8.
1341length() used on @g (did you mean "scalar(@g)"?) at - line 9.
1342########
1343# op.c
1344use warnings 'syntax' ;
1345join /---/, 'x', 'y', 'z';
1346EXPECT
1347/---/ should probably be written as "---" at - line 3.
1348########
1349# op.c
1350use utf8;
1351use open qw( :utf8 :std );
1352use warnings 'syntax' ;
1353join /~~~/, 'x', 'y', 'z';
1354EXPECT
1355/~~~/ should probably be written as "~~~" at - line 5.
1356########
1357# op.c [Perl_peep]
1358use warnings 'prototype' ;
1359fred() ;
1360sub fred ($$) {}
1361no warnings 'prototype' ;
1362joe() ;
1363sub joe ($$) {}
1364EXPECT
1365main::fred() called too early to check prototype at - line 3.
1366########
1367# op.c [Perl_newATTRSUB]
1368--FILE-- abc.pm
1369use warnings 'void' ;
1370BEGIN { $| = 1; print "in begin\n"; }
1371CHECK { print "in check\n"; }
1372INIT { print "in init\n"; }
1373END { print "in end\n"; }
1374print "in mainline\n";
13751;
1376--FILE--
1377use abc;
1378delete $INC{"abc.pm"};
1379require abc;
1380do "abc.pm";
1381EXPECT
1382in begin
1383in mainline
1384in check
1385in init
1386in begin
1387Too late to run CHECK block at abc.pm line 3.
1388Too late to run INIT block at abc.pm line 4.
1389in mainline
1390in begin
1391Too late to run CHECK block at abc.pm line 3.
1392Too late to run INIT block at abc.pm line 4.
1393in mainline
1394in end
1395in end
1396in end
1397########
1398# op.c [Perl_newATTRSUB]
1399--FILE-- abc.pm
1400no warnings 'void' ;
1401BEGIN { $| = 1; print "in begin\n"; }
1402CHECK { print "in check\n"; }
1403INIT { print "in init\n"; }
1404END { print "in end\n"; }
1405print "in mainline\n";
14061;
1407--FILE--
1408BEGIN { unshift @INC, '.' }
1409require abc;
1410do "abc.pm";
1411EXPECT
1412in begin
1413in mainline
1414in begin
1415in mainline
1416in end
1417in end
1418########
1419# op.c
1420my @x;
1421use warnings 'syntax' ;
1422push(@x);
1423unshift(@x);
1424no warnings 'syntax' ;
1425push(@x);
1426unshift(@x);
1427EXPECT
1428Useless use of push with no values at - line 4.
1429Useless use of unshift with no values at - line 5.
1430########
1431# op.c
1432# 20020401 mjd@plover.com at suggestion of jfriedl@yahoo.com
1433use warnings 'regexp';
1434split /blah/g, "blah";
1435no warnings 'regexp';
1436split /blah/g, "blah";
1437EXPECT
1438Use of /g modifier is meaningless in split at - line 4.
1439########
1440use feature "bitwise";
1441$_ = $_ | $_;
1442$_ = $_ & $_;
1443$_ = $_ ^ $_;
1444$_ = ~$_;
1445$_ = $_ |. $_;
1446$_ = $_ &. $_;
1447$_ = $_ ^. $_;
1448$_ = ~.$_;
1449$_ |= $_;
1450$_ &= $_;
1451$_ ^= $_;
1452$_ |.= $_;
1453$_ &.= $_;
1454$_ ^.= $_;
1455use warnings "experimental::bitwise";
1456$_ = $_ | $_;
1457$_ = $_ & $_;
1458$_ = $_ ^ $_;
1459$_ = ~$_;
1460$_ = $_ |. $_;
1461$_ = $_ &. $_;
1462$_ = $_ ^. $_;
1463$_ = ~.$_;
1464$_ |= $_;
1465$_ &= $_;
1466$_ ^= $_;
1467$_ |.= $_;
1468$_ &.= $_;
1469$_ ^.= $_;
1470no warnings "experimental::bitwise";
1471$_ = $_ | $_;
1472$_ = $_ & $_;
1473$_ = $_ ^ $_;
1474$_ = ~$_;
1475$_ = $_ |. $_;
1476$_ = $_ &. $_;
1477$_ = $_ ^. $_;
1478$_ = ~.$_;
1479$_ |= $_;
1480$_ &= $_;
1481$_ ^= $_;
1482$_ |.= $_;
1483$_ &.= $_;
1484$_ ^.= $_;
1485EXPECT
1486########
1487# op.c
1488use warnings 'precedence';
1489$a = $b & $c == $d;
1490$a = $b ^ $c != $d;
1491$a = $b | $c > $d;
1492$a = $b < $c & $d;
1493$a = $b >= $c ^ $d;
1494$a = $b <= $c | $d;
1495$a = $b <=> $c & $d;
1496$a &= $b == $c; $a |= $b == $c; $a ^= $b == $c; # shouldn't warn
1497{
1498 use experimental 'bitwise';
1499 $a = $b & $c == $d;
1500 $a = $b ^ $c != $d;
1501 $a = $b | $c > $d;
1502 $a = $b < $c & $d;
1503 $a = $b >= $c ^ $d;
1504 $a = $b <= $c | $d;
1505 $a = $b <=> $c & $d;
1506 $a &= $b == $c; $a |= $b == $c; $a ^= $b == $c; # shouldn't warn
1507 $a = $b &. $c == $d;
1508 $a = $b ^. $c != $d;
1509 $a = $b |. $c > $d;
1510 $a = $b < $c &. $d;
1511 $a = $b >= $c ^. $d;
1512 $a = $b <= $c |. $d;
1513 $a = $b <=> $c &. $d;
1514 $a &.= $b == $c; $a |.= $b == $c; $a ^.= $b == $c; # shouldn't warn
1515}
1516no warnings 'precedence';
1517$a = $b & $c == $d;
1518$a = $b ^ $c != $d;
1519$a = $b | $c > $d;
1520$a = $b < $c & $d;
1521$a = $b >= $c ^ $d;
1522$a = $b <= $c | $d;
1523$a = $b <=> $c & $d;
1524{
1525 use experimental 'bitwise';
1526 $a = $b & $c == $d;
1527 $a = $b ^ $c != $d;
1528 $a = $b | $c > $d;
1529 $a = $b < $c & $d;
1530 $a = $b >= $c ^ $d;
1531 $a = $b <= $c | $d;
1532 $a = $b <=> $c & $d;
1533 $a &= $b == $c; $a |= $b == $c; $a ^= $b == $c; # shouldn't warn
1534 $a = $b &. $c == $d;
1535 $a = $b ^. $c != $d;
1536 $a = $b |. $c > $d;
1537 $a = $b < $c &. $d;
1538 $a = $b >= $c ^. $d;
1539 $a = $b <= $c |. $d;
1540 $a = $b <=> $c &. $d;
1541 $a &.= $b == $c; $a |.= $b == $c; $a ^.= $b == $c; # shouldn't warn
1542}
1543EXPECT
1544Possible precedence problem on bitwise & operator at - line 3.
1545Possible precedence problem on bitwise ^ operator at - line 4.
1546Possible precedence problem on bitwise | operator at - line 5.
1547Possible precedence problem on bitwise & operator at - line 6.
1548Possible precedence problem on bitwise ^ operator at - line 7.
1549Possible precedence problem on bitwise | operator at - line 8.
1550Possible precedence problem on bitwise & operator at - line 9.
1551Possible precedence problem on bitwise & operator at - line 13.
1552Possible precedence problem on bitwise ^ operator at - line 14.
1553Possible precedence problem on bitwise | operator at - line 15.
1554Possible precedence problem on bitwise & operator at - line 16.
1555Possible precedence problem on bitwise ^ operator at - line 17.
1556Possible precedence problem on bitwise | operator at - line 18.
1557Possible precedence problem on bitwise & operator at - line 19.
1558Possible precedence problem on bitwise &. operator at - line 21.
1559Possible precedence problem on bitwise ^. operator at - line 22.
1560Possible precedence problem on bitwise |. operator at - line 23.
1561Possible precedence problem on bitwise &. operator at - line 24.
1562Possible precedence problem on bitwise ^. operator at - line 25.
1563Possible precedence problem on bitwise |. operator at - line 26.
1564Possible precedence problem on bitwise &. operator at - line 27.
1565########
1566# op.c
1567use integer;
1568use warnings 'precedence';
1569$a = $b & $c == $d;
1570$a = $b ^ $c != $d;
1571$a = $b | $c > $d;
1572$a = $b < $c & $d;
1573$a = $b >= $c ^ $d;
1574$a = $b <= $c | $d;
1575$a = $b <=> $c & $d;
1576no warnings 'precedence';
1577$a = $b & $c == $d;
1578$a = $b ^ $c != $d;
1579$a = $b | $c > $d;
1580$a = $b < $c & $d;
1581$a = $b >= $c ^ $d;
1582$a = $b <= $c | $d;
1583$a = $b <=> $c & $d;
1584EXPECT
1585Possible precedence problem on bitwise & operator at - line 4.
1586Possible precedence problem on bitwise ^ operator at - line 5.
1587Possible precedence problem on bitwise | operator at - line 6.
1588Possible precedence problem on bitwise & operator at - line 7.
1589Possible precedence problem on bitwise ^ operator at - line 8.
1590Possible precedence problem on bitwise | operator at - line 9.
1591Possible precedence problem on bitwise & operator at - line 10.
1592########
1593# op.c
1594
1595# ok	=> local() has desired effect;
1596# ignore=> local() silently ignored
1597
1598use warnings 'syntax';
1599
1600local(undef);		# OP_UNDEF		ignore
1601sub lval : lvalue {};
1602local(lval());		# OP_ENTERSUB
1603local($x **= 1);	# OP_POW
1604local($x *=  1);	# OP_MULTIPLY
1605local($x /=  1);	# OP_DIVIDE
1606local($x %=  1);	# OP_MODULO
1607local($x x=  1);	# OP_REPEAT
1608local($x +=  1);	# OP_ADD
1609local($x -=  1);	# OP_SUBTRACT
1610local($x .=  1);	# OP_CONCAT
1611local($x <<= 1);	# OP_LEFT_SHIFT
1612local($x >>= 1);	# OP_RIGHT_SHIFT
1613local($x &=  1);	# OP_BIT_AND
1614local($x ^=  1);	# OP_BIT_XOR
1615local($x |=  1);	# OP_BIT_OR
1616{
1617    use integer;
1618    local($x *= 1);	# OP_I_MULTIPLY
1619    local($x /= 1);	# OP_I_DIVIDE
1620    local($x %= 1);	# OP_I_MODULO
1621    local($x += 1);	# OP_I_ADD
1622    local($x -= 1);	# OP_I_SUBTRACT
1623}
1624local($x?$y:$z) = 1;	# OP_COND_EXPR		ok
1625# these two are fatal run-time errors instead
1626#local(@$a);		# OP_RV2AV		ok
1627#local(%$a);		# OP_RV2HV		ok
1628local(*a);		# OP_RV2GV		ok
1629local(@a[1,2]);		# OP_ASLICE		ok
1630local(@a{1,2});		# OP_HSLICE		ok
1631local(@a = (1,2));	# OP_AASSIGN
1632local($$x);		# OP_RV2SV		ok
1633local($#a);		# OP_AV2ARYLEN
1634local($x =   1);	# OP_SASSIGN
1635local($x &&= 1);	# OP_ANDASSIGN
1636local($x ||= 1);	# OP_ORASSIGN
1637local($x //= 1);	# OP_DORASSIGN
1638local($a[0]);		# OP_AELEMFAST		ok
1639
1640local(substr($x,0,1));	# OP_SUBSTR
1641local(pos($x));		# OP_POS
1642local(vec($x,0,1));	# OP_VEC
1643local($a[$b]);		# OP_AELEM		ok
1644local($a{$b});		# OP_HELEM		ok
1645
1646no warnings 'syntax';
1647EXPECT
1648Useless localization of subroutine entry at - line 10.
1649Useless localization of exponentiation (**) at - line 11.
1650Useless localization of multiplication (*) at - line 12.
1651Useless localization of division (/) at - line 13.
1652Useless localization of modulus (%) at - line 14.
1653Useless localization of repeat (x) at - line 15.
1654Useless localization of addition (+) at - line 16.
1655Useless localization of subtraction (-) at - line 17.
1656Useless localization of concatenation (.) or string at - line 18.
1657Useless localization of left bitshift (<<) at - line 19.
1658Useless localization of right bitshift (>>) at - line 20.
1659Useless localization of bitwise and (&) at - line 21.
1660Useless localization of bitwise xor (^) at - line 22.
1661Useless localization of bitwise or (|) at - line 23.
1662Useless localization of integer multiplication (*) at - line 26.
1663Useless localization of integer division (/) at - line 27.
1664Useless localization of integer modulus (%) at - line 28.
1665Useless localization of integer addition (+) at - line 29.
1666Useless localization of integer subtraction (-) at - line 30.
1667Useless localization of list assignment at - line 39.
1668Useless localization of array length at - line 41.
1669Useless localization of scalar assignment at - line 42.
1670Useless localization of logical and assignment (&&=) at - line 43.
1671Useless localization of logical or assignment (||=) at - line 44.
1672Useless localization of defined or assignment (//=) at - line 45.
1673Useless localization of substr at - line 48.
1674Useless localization of match position at - line 49.
1675Useless localization of vec at - line 50.
1676########
1677# op.c
1678# these shouldn't warn
1679our $x if 0;
1680our $x unless 0;
1681if (0) { my $w1 }
1682if (my $w2) { $a=1 }
1683if ($a && (my $w3 = 1)) {$a = 2}
1684
1685EXPECT
1686########
1687# op.c
1688use warnings 'void';
1689@x = split /y/, "z";
1690$x = split /y/, "z";
1691     split /y/, "z";
1692no warnings 'void';
1693@x = split /y/, "z";
1694$x = split /y/, "z";
1695     split /y/, "z";
1696EXPECT
1697Useless use of split in void context at - line 5.
1698########
1699# op.c
1700use warnings 'redefine' ;
1701use utf8;
1702use open qw( :utf8 :std );
1703sub frèd {}
1704sub frèd {}
1705no warnings 'redefine' ;
1706sub frèd {}
1707EXPECT
1708Subroutine frèd redefined at - line 6.
1709########
1710# op.c
1711use warnings 'redefine' ;
1712use utf8;
1713use open qw( :utf8 :std );
1714sub frèd () { 1 }
1715sub frèd () { 1 }
1716no warnings 'redefine' ;
1717sub frèd () { 1 }
1718EXPECT
1719Constant subroutine frèd redefined at - line 6.
1720########
1721# op.c
1722use utf8;
1723use open qw( :utf8 :std );
1724sub frèd () { 1 }
1725sub frèd () { 2 }
1726EXPECT
1727Constant subroutine frèd redefined at - line 5.
1728########
1729# op.c
1730use utf8;
1731use open qw( :utf8 :std );
1732sub frèd () { 1 }
1733*frèd = sub () { 2 };
1734EXPECT
1735Constant subroutine main::frèd redefined at - line 5.
1736########
1737# op.c
1738use warnings 'redefine' ;
1739use utf8;
1740use open qw( :utf8 :std );
1741sub ᚠርƊ {}
1742sub ᚠርƊ {}
1743no warnings 'redefine' ;
1744sub ᚠርƊ {}
1745EXPECT
1746Subroutine ᚠርƊ redefined at - line 6.
1747########
1748# op.c
1749use warnings 'redefine' ;
1750use utf8;
1751use open qw( :utf8 :std );
1752sub ᚠርƊ () { 1 }
1753sub ᚠርƊ () { 1 }
1754no warnings 'redefine' ;
1755sub ᚠርƊ () { 1 }
1756EXPECT
1757Constant subroutine ᚠርƊ redefined at - line 6.
1758########
1759# op.c
1760use utf8;
1761use open qw( :utf8 :std );
1762sub ᚠርƊ () { 1 }
1763sub ᚠርƊ () { 2 }
1764EXPECT
1765Constant subroutine ᚠርƊ redefined at - line 5.
1766########
1767# op.c
1768use utf8;
1769use open qw( :utf8 :std );
1770sub ᚠርƊ () { 1 }
1771*ᚠርƊ = sub () { 2 };
1772EXPECT
1773Constant subroutine main::ᚠርƊ redefined at - line 5.
1774########
1775# OPTION regex
1776sub DynaLoader::dl_error {};
1777use warnings;
1778# We're testing that the warnings report the same line number:
1779eval <<'EOC' or die $@;
1780{
1781    DynaLoader::boot_DynaLoader("DynaLoader");
1782}
1783EOC
1784eval <<'EOC' or die $@;
1785BEGIN {
1786    DynaLoader::boot_DynaLoader("DynaLoader");
1787}
17881
1789EOC
1790EXPECT
1791OPTION regex
1792\ASubroutine DynaLoader::dl_error redefined at \(eval 1\) line 2\.
1793?(?s).*
1794Subroutine DynaLoader::dl_error redefined at \(eval 2\) line 2\.
1795########
1796# op.c
1797use warnings;
1798sub do_warn_1  { return $a or $b; }
1799sub do_warn_2  { return $a and $b; }
1800sub do_warn_3  { return $a xor $b; }
1801sub do_warn_4  { die $a or $b; }
1802sub do_warn_5  { die $a and $b; }
1803sub do_warn_6  { die $a xor $b; }
1804sub do_warn_7  { exit $a or $b; }
1805sub do_warn_8  { exit $a and $b; }
1806sub do_warn_9  { exit $a xor $b; }
1807
1808# Since exit is an unary operator, it is even stronger than
1809# || and &&.
1810sub do_warn_10 { exit $a || $b; }
1811sub do_warn_11 { exit $a && $b; }
1812
1813sub do_warn_12 { goto $a or $b; }
1814sub do_warn_13 { goto $a and $b; }
1815sub do_warn_14 { goto $a xor $b; }
1816sub do_warn_15 { next $a or $b while(1);  }
1817sub do_warn_16 { next $a and $b while(1); }
1818sub do_warn_17 { next $a xor $b while(1); }
1819sub do_warn_18 { last $a or $b while(1);  }
1820sub do_warn_19 { last $a and $b while(1); }
1821sub do_warn_20 { last $a xor $b while(1); }
1822sub do_warn_21 { redo $a or $b while(1); }
1823sub do_warn_22 { redo $a and $b while(1); }
1824sub do_warn_23 { redo $a xor $b while(1); }
1825# These get re-written to "(return/die $a) and $b"
1826sub do_warn_24 { $b if return $a; }
1827sub do_warn_25 { $b if die $a; }
1828EXPECT
1829Possible precedence issue with control flow operator at - line 3.
1830Possible precedence issue with control flow operator at - line 4.
1831Possible precedence issue with control flow operator at - line 5.
1832Possible precedence issue with control flow operator at - line 6.
1833Possible precedence issue with control flow operator at - line 7.
1834Possible precedence issue with control flow operator at - line 8.
1835Possible precedence issue with control flow operator at - line 9.
1836Possible precedence issue with control flow operator at - line 10.
1837Possible precedence issue with control flow operator at - line 11.
1838Possible precedence issue with control flow operator at - line 15.
1839Possible precedence issue with control flow operator at - line 16.
1840Possible precedence issue with control flow operator at - line 18.
1841Possible precedence issue with control flow operator at - line 19.
1842Possible precedence issue with control flow operator at - line 20.
1843Possible precedence issue with control flow operator at - line 21.
1844Possible precedence issue with control flow operator at - line 22.
1845Possible precedence issue with control flow operator at - line 23.
1846Possible precedence issue with control flow operator at - line 24.
1847Possible precedence issue with control flow operator at - line 25.
1848Possible precedence issue with control flow operator at - line 26.
1849Possible precedence issue with control flow operator at - line 27.
1850Possible precedence issue with control flow operator at - line 28.
1851Possible precedence issue with control flow operator at - line 29.
1852Possible precedence issue with control flow operator at - line 31.
1853Possible precedence issue with control flow operator at - line 32.
1854########
1855# op.c
1856#  (same as above, except these should not warn)
1857use constant FEATURE => 1;
1858use constant MISSING_FEATURE => 0;
1859
1860sub dont_warn_1  { MISSING_FEATURE and return or dont_warn_3(); }
1861sub dont_warn_2  { FEATURE || return and dont_warn_3(); }
1862sub dont_warn_3  { not FEATURE and return or dont_warn_3(); }
1863sub dont_warn_4  { !MISSING_FEATURE || return and dont_warn_3(); }
1864sub dont_warn_5  { MISSING_FEATURE and die or dont_warn_3(); }
1865sub dont_warn_6  { FEATURE || die and dont_warn_3(); }
1866sub dont_warn_7  { not FEATURE and die or dont_warn_3(); }
1867sub dont_warn_8  { !MISSING_FEATURE || die and dont_warn_3(); }
1868sub dont_warn_9  { MISSING_FEATURE and goto $a or dont_warn_3(); }
1869sub dont_warn_10 { FEATURE || goto $a and dont_warn_3(); }
1870sub dont_warn_11 { not FEATURE and goto $a or dont_warn_3(); }
1871sub dont_warn_12 { !MISSING_FEATURE || goto $a and dont_warn_3(); }
1872
1873sub dont_warn_13 { MISSING_FEATURE and exit $a or dont_warn_3(); }
1874sub dont_warn_14 { FEATURE || exit $a and dont_warn_3(); }
1875sub dont_warn_15 { not FEATURE and exit $a or dont_warn_3(); }
1876sub dont_warn_16 { !MISSING_FEATURE || exit $a and dont_warn_3(); }
1877
1878sub dont_warn_17 { MISSING_FEATURE and next or dont_warn_3() while(1); }
1879sub dont_warn_18 { FEATURE || next and dont_warn_3() while(1); }
1880sub dont_warn_19 { not FEATURE and next or dont_warn_3() while(1); }
1881sub dont_warn_20 { !MISSING_FEATURE || next and dont_warn_3() while(1); }
1882sub dont_warn_21 { MISSING_FEATURE and redo or dont_warn_3() while(1); }
1883sub dont_warn_22 { FEATURE || redo and dont_warn_3() while(1); }
1884sub dont_warn_23 { not FEATURE and redo or dont_warn_3() while(1); }
1885sub dont_warn_24 { !MISSING_FEATURE || redo and dont_warn_3() while(1); }
1886sub dont_warn_25 { MISSING_FEATURE and last or dont_warn_3() while(1); }
1887sub dont_warn_26 { FEATURE || last and dont_warn_3() while(1); }
1888sub dont_warn_27 { not FEATURE and last or dont_warn_3() while(1); }
1889sub dont_warn_28 { !MISSING_FEATURE || last and dont_warn_3() while(1); }
1890
1891# These are weird, but at least not ambiguous.
1892sub dont_warn_29 { return ($a or $b); }
1893sub dont_warn_30 { return ($a and $b); }
1894sub dont_warn_31 { return ($a xor $b); }
1895sub dont_warn_32 { die ($a or $b); }
1896sub dont_warn_33 { die ($a and $b); }
1897sub dont_warn_34 { die ($a xor $b); }
1898sub dont_warn_35 { goto ($a or $b); }
1899sub dont_warn_36 { goto ($a and $b); }
1900sub dont_warn_37 { goto ($a xor $b); }
1901sub dont_warn_38 { next ($a or $b) while(1);  }
1902sub dont_warn_39 { next ($a and $b) while(1); }
1903sub dont_warn_40 { next ($a xor $b) while(1); }
1904sub dont_warn_41 { last ($a or $b) while(1);  }
1905sub dont_warn_42 { last ($a and $b) while(1); }
1906sub dont_warn_43 { last ($a xor $b) while(1); }
1907sub dont_warn_44 { redo ($a or $b) while(1);  }
1908sub dont_warn_45 { redo ($a and $b) while(1); }
1909sub dont_warn_46 { redo ($a xor $b) while(1); }
1910EXPECT
1911########
1912use feature "signatures";
1913sub aaa { 2 }
1914sub bbb ($a) { 4 }
1915$aaa = sub { 2 };
1916$bbb = sub ($a) { 4 };
1917EXPECT
1918The signatures feature is experimental at - line 3.
1919The signatures feature is experimental at - line 5.
1920########
1921no warnings "experimental::signatures";
1922use feature "signatures";
1923sub aaa { 2 }
1924sub bbb ($a) { 4 }
1925$aaa = sub { 2 };
1926$bbb = sub ($a) { 4 };
1927EXPECT
1928########
1929use warnings 'numeric';
1930my $c = -4.5;
1931my $a = "y" x $c;
1932my $b = "y" x -3;
1933no warnings 'numeric';
1934my $d = "y" x $c;
1935my $e = "y" x -3;
1936no warnings 'numeric';
1937EXPECT
1938Negative repeat count does nothing at - line 3.
1939Negative repeat count does nothing at - line 4.
1940########
1941use Config;
1942my $non_ieee_fp = ($Config{doublekind} == 9 ||
1943                   $Config{doublekind} == 10 ||
1944                   $Config{doublekind} == 11);
1945if ($non_ieee_fp) {
1946    print <<EOM ;
1947SKIPPED
1948# No inf/nan support
1949EOM
1950    exit ;
1951}
1952my $a = "inf" + 0;
1953my $b = -$a;
1954my $c = "nan" + 0;
1955use warnings 'numeric';
1956my $x = "x" x $a;
1957my $y = "y" x $b;
1958my $z = "z" x $c;
1959no warnings 'numeric';
1960my $x = "x" x $a;
1961my $y = "y" x $b;
1962my $z = "z" x $c;
1963no warnings 'numeric';
1964EXPECT
1965Non-finite repeat count does nothing at - line 16.
1966Non-finite repeat count does nothing at - line 17.
1967Non-finite repeat count does nothing at - line 18.
1968########
1969# NAME warn on stat @array
1970@foo = ("op/stat.t");
1971stat @foo;
1972my @bar = @foo;
1973stat @bar;
1974my $ref = \@foo;
1975stat @$ref;
1976use warnings 'syntax';
1977stat @foo;
1978stat @bar;
1979stat @$ref;
1980EXPECT
1981Array passed to stat will be coerced to a scalar (did you want stat $foo[0]?) at - line 8.
1982Array passed to stat will be coerced to a scalar (did you want stat $bar[0]?) at - line 9.
1983Array passed to stat will be coerced to a scalar at - line 10.
1984
1985########
1986# NAME barewords and conditionals near constant folding
1987use warnings;
1988my $x1 = !a || !b; # no "in conditional" warnings
1989my $x2 = !A || !B; # warning-free, because upper-case won't clash
1990EXPECT
1991Unquoted string "a" may clash with future reserved word at - line 2.
1992Unquoted string "b" may clash with future reserved word at - line 2.
1993########
1994# RT #6870: Odd parsing of do...for...
1995# This was really more a tokenizer bug, but it manifests as spurious warnings
1996use warnings;
1997no warnings 'reserved';
1998$a=do xa for ax;
1999do "xa" for ax;
2000do xa for ax;
2001do xa for "ax";
2002do xa for sin(1);
2003do xa for (sin(1));
2004do xa for "sin";
2005do xa for qq(sin);
2006do xa for my $a;
2007do xa for my @a;
2008EXPECT
2009########
2010# [perl #125493
2011use warnings;
2012$_="3.14159";
2013tr/0-9/\x{6F0}-\x{6F9}/;
2014EXPECT
2015########
2016# Useless use of concatenation should appear for any number of args
2017use warnings;
2018($a, $b, $c) = (42)x3;
2019$a.$b;
2020$a.$b.$c;
2021EXPECT
2022Useless use of concatenation (.) or string in void context at - line 4.
2023Useless use of concatenation (.) or string in void context at - line 5.
2024########
2025# PL_curcop tracked correctly in Perl_scalar()
2026use warnings;
2027my $scalar = do {
2028    no warnings 'void';
2029    1,2,3,4,5;
2030};
2031EXPECT
2032########
2033# PL_curcop tracked correctly in Perl_list()
2034use warnings;
2035my @array = do {
2036    no warnings 'void';
2037    1,2,3,4,5;
2038};
2039EXPECT
2040########
2041# TODO PL_curcop restored correctly in Perl_scalar()
2042use warnings;
2043my $scalar = do {
2044    my $x = 1;
2045    11,12,
2046    do {
2047        no warnings 'void';
2048        my $x = 2;
2049        21,22,
2050    },
2051    31,32,
2052    do {
2053        my $x = 3;
2054        41,42,
2055    },
2056    51,52
2057};
2058EXPECT
2059Useless use of a constant (11) in void context at - line 5.
2060Useless use of a constant (12) in void context at - line 5.
2061Useless use of a constant (31) in void context at - line 11.
2062Useless use of a constant (32) in void context at - line 11.
2063Useless use of a constant (41) in void context at - line 14.
2064Useless use of a constant (42) in void context at - line 14.
2065Useless use of a constant (51) in void context at - line 16.
2066