Fully qualify in warning message the name of a subroutine redefined
[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;
599cee73 60EXPECT
2dd78f96 61print() on unopened filehandle abc at - line 4.
599cee73 62########
767a6a26 63# pp_hot.c [pp_print]
4438c4b7 64use warnings 'io' ;
977289e4 65# There is no guarantee that STDOUT is output only, or STDIN input only.
66# Certainly on some BSDs (at least FreeBSD, Darwin, BSDi) file descriptors
67# 1 and 2 are opened read/write on the tty, and the IO layers may reflect this.
68# So we must make our own file handle that is read only.
69my $file = "./xcv" ; unlink $file ;
70open (FH, ">$file") or die $! ;
71close FH or die $! ;
72die "There is no file $file" unless -f $file ;
73open (FH, "<$file") or die $! ;
74print FH "anc" ;
75open(FOO, "<&FH") or die $! ;
76print FOO "anc" ;
37bd1396 77no warnings 'io' ;
977289e4 78print FH "anc" ;
79print FOO "anc" ;
80use warnings 'io' ;
81print FH "anc" ;
82print FOO "anc" ;
83close (FH) or die $! ;
84close (FOO) or die $! ;
85unlink $file ;
599cee73 86EXPECT
977289e4 87Filehandle FH opened only for input at - line 12.
88Filehandle FOO opened only for input at - line 14.
89Filehandle FH opened only for input at - line 19.
90Filehandle FOO opened only for input at - line 20.
599cee73 91########
767a6a26 92# pp_hot.c [pp_print]
4438c4b7 93use warnings 'closed' ;
599cee73 94close STDIN ;
95print STDIN "anc";
69282e91 96opendir STDIN, ".";
97print STDIN "anc";
98closedir STDIN;
4438c4b7 99no warnings 'closed' ;
0453d815 100print STDIN "anc";
69282e91 101opendir STDIN, ".";
102print STDIN "anc";
599cee73 103EXPECT
43693395 104print() on closed filehandle STDIN at - line 4.
105print() on closed filehandle STDIN at - line 6.
106 (Are you trying to call print() on dirhandle STDIN?)
599cee73 107########
767a6a26 108# pp_hot.c [pp_rv2av]
4438c4b7 109use warnings 'uninitialized' ;
599cee73 110my $a = undef ;
0453d815 111my @b = @$a;
4438c4b7 112no warnings 'uninitialized' ;
0453d815 113my @c = @$a;
599cee73 114EXPECT
b89fed5f 115Use of uninitialized value in array dereference at - line 4.
599cee73 116########
767a6a26 117# pp_hot.c [pp_rv2hv]
4438c4b7 118use warnings 'uninitialized' ;
599cee73 119my $a = undef ;
0453d815 120my %b = %$a;
4438c4b7 121no warnings 'uninitialized' ;
0453d815 122my %c = %$a;
599cee73 123EXPECT
b89fed5f 124Use of uninitialized value in hash dereference at - line 4.
599cee73 125########
767a6a26 126# pp_hot.c [pp_aassign]
e476b1b5 127use warnings 'misc' ;
599cee73 128my %X ; %X = (1,2,3) ;
e476b1b5 129no warnings 'misc' ;
0453d815 130my %Y ; %Y = (1,2,3) ;
599cee73 131EXPECT
132Odd number of elements in hash assignment at - line 3.
133########
767a6a26 134# pp_hot.c [pp_aassign]
e476b1b5 135use warnings 'misc' ;
599cee73 136my %X ; %X = [1 .. 3] ;
e476b1b5 137no warnings 'misc' ;
0453d815 138my %Y ; %Y = [1 .. 3] ;
599cee73 139EXPECT
140Reference found where even-sized list expected at - line 3.
141########
767a6a26 142# pp_hot.c [Perl_do_readline]
4438c4b7 143use warnings 'closed' ;
69282e91 144close STDIN ; $a = <STDIN> ;
145opendir STDIN, "." ; $a = <STDIN> ;
146closedir STDIN;
4438c4b7 147no warnings 'closed' ;
69282e91 148opendir STDIN, "." ; $a = <STDIN> ;
0453d815 149$a = <STDIN> ;
599cee73 150EXPECT
43693395 151readline() on closed filehandle STDIN at - line 3.
152readline() on closed filehandle STDIN at - line 4.
153 (Are you trying to call readline() on dirhandle STDIN?)
599cee73 154########
767a6a26 155# pp_hot.c [Perl_do_readline]
156use warnings 'io' ;
157my $file = "./xcv" ; unlink $file ;
977289e4 158open (FH, ">$file") or die $! ;
767a6a26 159my $a = <FH> ;
160no warnings 'io' ;
161$a = <FH> ;
977289e4 162use warnings 'io' ;
163open(FOO, ">&FH") or die $! ;
164$a = <FOO> ;
165no warnings 'io' ;
166$a = <FOO> ;
167use warnings 'io' ;
168$a = <FOO> ;
169$a = <FH> ;
170close (FH) or die $! ;
171close (FOO) or die $! ;
767a6a26 172unlink $file ;
173EXPECT
43693395 174Filehandle FH opened only for output at - line 5.
977289e4 175Filehandle FOO opened only for output at - line 10.
176Filehandle FOO opened only for output at - line 14.
177Filehandle FH opened only for output at - line 15.
767a6a26 178########
179# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 180use warnings 'recursion' ;
599cee73 181sub fred
182{
183 fred() if $a++ < 200
184}
4a925ff6 185{
186 local $SIG{__WARN__} = sub {
187 die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
188 };
189 fred();
190}
599cee73 191EXPECT
4a925ff6 192ok
599cee73 193########
767a6a26 194# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 195no warnings 'recursion' ;
0453d815 196sub fred
197{
198 fred() if $a++ < 200
199}
200{
201 local $SIG{__WARN__} = sub {
202 die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
203 };
204 fred();
205}
206EXPECT
207
208########
767a6a26 209# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 210use warnings 'recursion' ;
599cee73 211$b = sub
212{
213 &$b if $a++ < 200
214} ;
215
216&$b ;
217EXPECT
218Deep recursion on anonymous subroutine at - line 5.
0453d815 219########
767a6a26 220# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 221no warnings 'recursion' ;
0453d815 222$b = sub
223{
224 &$b if $a++ < 200
225} ;
226
227&$b ;
228EXPECT
6bc102ca 229########
230# pp_hot.c [pp_concat]
8d6d96c1 231use warnings 'uninitialized';
232my($x, $y);
233sub a { shift }
234a($x . "x"); # should warn once
235a($x . $y); # should warn twice
236$x .= $y; # should warn once
237$y .= $y; # should warn once
238EXPECT
239Use of uninitialized value in concatenation (.) or string at - line 5.
240Use of uninitialized value in concatenation (.) or string at - line 6.
241Use of uninitialized value in concatenation (.) or string at - line 6.
242Use of uninitialized value in concatenation (.) or string at - line 7.
243Use of uninitialized value in concatenation (.) or string at - line 8.
244########
245# pp_hot.c [pp_concat]
e476b1b5 246use warnings 'y2k';
6bc102ca 247use Config;
248BEGIN {
249 unless ($Config{ccflags} =~ /Y2KWARN/) {
250 print "SKIPPED\n# perl not built with -DPERL_Y2KWARN";
251 exit 0;
252 }
253}
254my $x;
255my $yy = 78;
256$x = "19$yy\n";
257$x = "19" . $yy . "\n";
258$x = "319$yy\n";
259$x = "319" . $yy . "\n";
777b0c87 260$yy = 19;
261$x = "ok $yy\n";
262$yy = 9;
263$x = 1 . $yy;
e476b1b5 264no warnings 'y2k';
6bc102ca 265$x = "19$yy\n";
266$x = "19" . $yy . "\n";
267EXPECT
268Possible Y2K bug: about to append an integer to '19' at - line 12.
269Possible Y2K bug: about to append an integer to '19' at - line 13.
d804643f 270########
271# pp_hot.c [pp_aelem]
272{
273use warnings 'misc';
274print $x[\1];
275}
276{
277no warnings 'misc';
278print $x[\1];
279}
280
281EXPECT
282OPTION regex
283Use of reference ".*" as array index at - line 4.
1f1cc344 284########
285# pp_hot.c [pp_aelem]
286package Foo;use overload q("") => sub {};package main;$a = bless {}, "Foo";
287$b = {};
288{
289use warnings 'misc';
290print $x[$a];
291print $x[$b];
292}
293{
294no warnings 'misc';
295print $x[$a];
296print $x[$b];
297}
298
299EXPECT
300OPTION regex
301Use of reference ".*" as array index at - line 7.