Include variable names in "Use of uninitialized value" warnings
[p5sagit/p5-mst-13.2.git] / t / lib / warnings / pp_hot
CommitLineData
767a6a26 1 pp_hot.c
599cee73 2
2dd78f96 3 print() on unopened filehandle abc [pp_print]
599cee73 4 $f = $a = "abc" ; print $f $a
5
767a6a26 6 Filehandle %s opened only for input [pp_print]
599cee73 7 print STDIN "abc" ;
8
767a6a26 9 Filehandle %s opened only for output [pp_print]
977289e4 10 $a = <STDOUT> ;
599cee73 11
9a7dcd9c 12 print() on closed filehandle %s [pp_print]
599cee73 13 close STDIN ; print STDIN "abc" ;
14
767a6a26 15 uninitialized [pp_rv2av]
599cee73 16 my $a = undef ; my @b = @$a
17
767a6a26 18 uninitialized [pp_rv2hv]
599cee73 19 my $a = undef ; my %b = %$a
20
767a6a26 21 Odd number of elements in hash list [pp_aassign]
599cee73 22 %X = (1,2,3) ;
23
767a6a26 24 Reference found where even-sized list expected [pp_aassign]
599cee73 25 $X = [ 1 ..3 ];
26
767a6a26 27 Filehandle %s opened only for output [Perl_do_readline]
28 open (FH, ">./xcv") ;
29 my $a = <FH> ;
30
31 glob failed (can't start child: %s) [Perl_do_readline] <<TODO
32
9a7dcd9c 33 readline() on closed filehandle %s [Perl_do_readline]
599cee73 34 close STDIN ; $a = <STDIN>;
35
790090df 36 readline() on closed filehandle %s [Perl_do_readline]
37 readline(NONESUCH);
38
767a6a26 39 glob failed (child exited with status %d%s) [Perl_do_readline] <<TODO
40
41 Deep recursion on subroutine \"%s\" [Perl_sub_crush_depth]
6bc102ca 42 sub fred { fred() if $a++ < 200} fred()
599cee73 43
767a6a26 44 Deep recursion on anonymous subroutine [Perl_sub_crush_depth]
6bc102ca 45 $a = sub { &$a if $a++ < 200} &$a
599cee73 46
6bc102ca 47 Possible Y2K bug: about to append an integer to '19' [pp_concat]
48 $x = "19$yy\n";
767a6a26 49
d804643f 50 Use of reference "%s" as array index [pp_aelem]
51 $x[\1]
52
599cee73 53__END__
767a6a26 54# pp_hot.c [pp_print]
4438c4b7 55use warnings 'unopened' ;
599cee73 56$f = $a = "abc" ;
0453d815 57print $f $a;
4438c4b7 58no warnings 'unopened' ;
0453d815 59print $f $a;
cf26e47f 60use warnings;
61no warnings 'unopened' ;
62print $f $a;
599cee73 63EXPECT
2dd78f96 64print() on unopened filehandle abc at - line 4.
599cee73 65########
767a6a26 66# pp_hot.c [pp_print]
4438c4b7 67use warnings 'io' ;
977289e4 68# There is no guarantee that STDOUT is output only, or STDIN input only.
69# Certainly on some BSDs (at least FreeBSD, Darwin, BSDi) file descriptors
70# 1 and 2 are opened read/write on the tty, and the IO layers may reflect this.
71# So we must make our own file handle that is read only.
72my $file = "./xcv" ; unlink $file ;
73open (FH, ">$file") or die $! ;
74close FH or die $! ;
75die "There is no file $file" unless -f $file ;
76open (FH, "<$file") or die $! ;
77print FH "anc" ;
78open(FOO, "<&FH") or die $! ;
79print FOO "anc" ;
37bd1396 80no warnings 'io' ;
977289e4 81print FH "anc" ;
82print FOO "anc" ;
83use warnings 'io' ;
84print FH "anc" ;
85print FOO "anc" ;
86close (FH) or die $! ;
87close (FOO) or die $! ;
88unlink $file ;
599cee73 89EXPECT
977289e4 90Filehandle FH opened only for input at - line 12.
91Filehandle FOO opened only for input at - line 14.
92Filehandle FH opened only for input at - line 19.
93Filehandle FOO opened only for input at - line 20.
599cee73 94########
767a6a26 95# pp_hot.c [pp_print]
4438c4b7 96use warnings 'closed' ;
599cee73 97close STDIN ;
98print STDIN "anc";
69282e91 99opendir STDIN, ".";
100print STDIN "anc";
101closedir STDIN;
4438c4b7 102no warnings 'closed' ;
0453d815 103print STDIN "anc";
69282e91 104opendir STDIN, ".";
105print STDIN "anc";
cf26e47f 106use warnings;
107no warnings 'closed' ;
108print STDIN "anc";
599cee73 109EXPECT
43693395 110print() on closed filehandle STDIN at - line 4.
111print() on closed filehandle STDIN at - line 6.
112 (Are you trying to call print() on dirhandle STDIN?)
599cee73 113########
f55e507d 114# pp_hot.c [pp_print]
115# [ID 20020425.012] from Dave Steiner <steiner@bakerst.rutgers.edu>
116# This goes segv on 5.7.3
117use warnings 'closed' ;
118my $fh = *STDOUT{IO};
119close STDOUT or die "Can't close STDOUT";
120print $fh "Shouldn't print anything, but shouldn't SEGV either\n";
121EXPECT
122print() on closed filehandle at - line 7.
123########
f62cb720 124# pp_hot.c [pp_print]
125package foo;
126use warnings 'closed';
127open my $fh1, "nonexistent";
128print $fh1 42;
129open $fh2, "nonexistent";
130print $fh2 42;
131open $bar::fh3, "nonexistent";
132print $bar::fh3 42;
133open bar::FH4, "nonexistent";
134print bar::FH4 42;
135EXPECT
136print() on closed filehandle $fh1 at - line 5.
137print() on closed filehandle $fh2 at - line 7.
138print() on closed filehandle $fh3 at - line 9.
139print() on closed filehandle FH4 at - line 11.
140########
767a6a26 141# pp_hot.c [pp_rv2av]
4438c4b7 142use warnings 'uninitialized' ;
599cee73 143my $a = undef ;
0453d815 144my @b = @$a;
4438c4b7 145no warnings 'uninitialized' ;
0453d815 146my @c = @$a;
599cee73 147EXPECT
29489e7c 148Use of uninitialized value $a in array dereference at - line 4.
599cee73 149########
767a6a26 150# pp_hot.c [pp_rv2hv]
4438c4b7 151use warnings 'uninitialized' ;
599cee73 152my $a = undef ;
0453d815 153my %b = %$a;
4438c4b7 154no warnings 'uninitialized' ;
0453d815 155my %c = %$a;
599cee73 156EXPECT
29489e7c 157Use of uninitialized value $a in hash dereference at - line 4.
599cee73 158########
767a6a26 159# pp_hot.c [pp_aassign]
e476b1b5 160use warnings 'misc' ;
599cee73 161my %X ; %X = (1,2,3) ;
e476b1b5 162no warnings 'misc' ;
0453d815 163my %Y ; %Y = (1,2,3) ;
599cee73 164EXPECT
165Odd number of elements in hash assignment at - line 3.
166########
767a6a26 167# pp_hot.c [pp_aassign]
e476b1b5 168use warnings 'misc' ;
599cee73 169my %X ; %X = [1 .. 3] ;
e476b1b5 170no warnings 'misc' ;
0453d815 171my %Y ; %Y = [1 .. 3] ;
599cee73 172EXPECT
173Reference found where even-sized list expected at - line 3.
174########
767a6a26 175# pp_hot.c [Perl_do_readline]
4438c4b7 176use warnings 'closed' ;
69282e91 177close STDIN ; $a = <STDIN> ;
178opendir STDIN, "." ; $a = <STDIN> ;
179closedir STDIN;
4438c4b7 180no warnings 'closed' ;
69282e91 181opendir STDIN, "." ; $a = <STDIN> ;
0453d815 182$a = <STDIN> ;
599cee73 183EXPECT
43693395 184readline() on closed filehandle STDIN at - line 3.
185readline() on closed filehandle STDIN at - line 4.
186 (Are you trying to call readline() on dirhandle STDIN?)
599cee73 187########
767a6a26 188# pp_hot.c [Perl_do_readline]
189use warnings 'io' ;
190my $file = "./xcv" ; unlink $file ;
977289e4 191open (FH, ">$file") or die $! ;
767a6a26 192my $a = <FH> ;
193no warnings 'io' ;
194$a = <FH> ;
977289e4 195use warnings 'io' ;
196open(FOO, ">&FH") or die $! ;
197$a = <FOO> ;
198no warnings 'io' ;
199$a = <FOO> ;
200use warnings 'io' ;
201$a = <FOO> ;
202$a = <FH> ;
203close (FH) or die $! ;
204close (FOO) or die $! ;
767a6a26 205unlink $file ;
206EXPECT
43693395 207Filehandle FH opened only for output at - line 5.
977289e4 208Filehandle FOO opened only for output at - line 10.
209Filehandle FOO opened only for output at - line 14.
210Filehandle FH opened only for output at - line 15.
767a6a26 211########
212# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 213use warnings 'recursion' ;
599cee73 214sub fred
215{
216 fred() if $a++ < 200
217}
4a925ff6 218{
219 local $SIG{__WARN__} = sub {
220 die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
221 };
222 fred();
223}
599cee73 224EXPECT
4a925ff6 225ok
599cee73 226########
767a6a26 227# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 228no warnings 'recursion' ;
0453d815 229sub fred
230{
231 fred() if $a++ < 200
232}
233{
234 local $SIG{__WARN__} = sub {
235 die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
236 };
237 fred();
238}
239EXPECT
240
241########
767a6a26 242# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 243use warnings 'recursion' ;
599cee73 244$b = sub
245{
246 &$b if $a++ < 200
247} ;
248
249&$b ;
250EXPECT
251Deep recursion on anonymous subroutine at - line 5.
0453d815 252########
767a6a26 253# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 254no warnings 'recursion' ;
0453d815 255$b = sub
256{
257 &$b if $a++ < 200
258} ;
259
260&$b ;
261EXPECT
6bc102ca 262########
263# pp_hot.c [pp_concat]
8d6d96c1 264use warnings 'uninitialized';
265my($x, $y);
266sub a { shift }
267a($x . "x"); # should warn once
268a($x . $y); # should warn twice
269$x .= $y; # should warn once
270$y .= $y; # should warn once
271EXPECT
29489e7c 272Use of uninitialized value $x in concatenation (.) or string at - line 5.
273Use of uninitialized value $y in concatenation (.) or string at - line 6.
274Use of uninitialized value $x in concatenation (.) or string at - line 6.
275Use of uninitialized value $y in concatenation (.) or string at - line 7.
276Use of uninitialized value $y in concatenation (.) or string at - line 8.
8d6d96c1 277########
278# pp_hot.c [pp_concat]
e476b1b5 279use warnings 'y2k';
6bc102ca 280use Config;
281BEGIN {
282 unless ($Config{ccflags} =~ /Y2KWARN/) {
283 print "SKIPPED\n# perl not built with -DPERL_Y2KWARN";
284 exit 0;
285 }
286}
287my $x;
288my $yy = 78;
289$x = "19$yy\n";
290$x = "19" . $yy . "\n";
291$x = "319$yy\n";
292$x = "319" . $yy . "\n";
777b0c87 293$yy = 19;
294$x = "ok $yy\n";
295$yy = 9;
296$x = 1 . $yy;
e476b1b5 297no warnings 'y2k';
6bc102ca 298$x = "19$yy\n";
299$x = "19" . $yy . "\n";
300EXPECT
301Possible Y2K bug: about to append an integer to '19' at - line 12.
302Possible Y2K bug: about to append an integer to '19' at - line 13.
d804643f 303########
304# pp_hot.c [pp_aelem]
305{
306use warnings 'misc';
307print $x[\1];
308}
309{
310no warnings 'misc';
311print $x[\1];
312}
313
314EXPECT
315OPTION regex
316Use of reference ".*" as array index at - line 4.
1f1cc344 317########
318# pp_hot.c [pp_aelem]
319package Foo;use overload q("") => sub {};package main;$a = bless {}, "Foo";
320$b = {};
321{
322use warnings 'misc';
323print $x[$a];
324print $x[$b];
325}
326{
327no warnings 'misc';
328print $x[$a];
329print $x[$b];
330}
331
332EXPECT
333OPTION regex
334Use of reference ".*" as array index at - line 7.