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 / pp_hot
CommitLineData
767a6a26 1 pp_hot.c
599cee73 2
2dd78f96 3 print() on unopened filehandle abc [pp_print]
599cee73
PM
4 $f = $a = "abc" ; print $f $a
5
767a6a26 6 Filehandle %s opened only for input [pp_print]
599cee73
PM
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
PM
13 close STDIN ; print STDIN "abc" ;
14
767a6a26 15 uninitialized [pp_rv2av]
599cee73
PM
16 my $a = undef ; my @b = @$a
17
767a6a26 18 uninitialized [pp_rv2hv]
599cee73
PM
19 my $a = undef ; my %b = %$a
20
767a6a26 21 Odd number of elements in hash list [pp_aassign]
599cee73
PM
22 %X = (1,2,3) ;
23
767a6a26 24 Reference found where even-sized list expected [pp_aassign]
599cee73
PM
25 $X = [ 1 ..3 ];
26
767a6a26
PM
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
PM
34 close STDIN ; $a = <STDIN>;
35
790090df
HS
36 readline() on closed filehandle %s [Perl_do_readline]
37 readline(NONESUCH);
38
767a6a26
PM
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
d804643f
SC
47 Use of reference "%s" as array index [pp_aelem]
48 $x[\1]
49
599cee73 50__END__
767a6a26 51# pp_hot.c [pp_print]
4438c4b7 52use warnings 'unopened' ;
599cee73 53$f = $a = "abc" ;
0453d815 54print $f $a;
4438c4b7 55no warnings 'unopened' ;
0453d815 56print $f $a;
cf26e47f
NC
57use warnings;
58no warnings 'unopened' ;
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
NC
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
NC
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
NC
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
PM
94close STDIN ;
95print STDIN "anc";
69282e91
GS
96opendir STDIN, ".";
97print STDIN "anc";
98closedir STDIN;
4438c4b7 99no warnings 'closed' ;
0453d815 100print STDIN "anc";
69282e91
GS
101opendir STDIN, ".";
102print STDIN "anc";
cf26e47f
NC
103use warnings;
104no warnings 'closed' ;
105print STDIN "anc";
599cee73 106EXPECT
43693395
GS
107print() on closed filehandle STDIN at - line 4.
108print() on closed filehandle STDIN at - line 6.
109 (Are you trying to call print() on dirhandle STDIN?)
599cee73 110########
f55e507d
NC
111# pp_hot.c [pp_print]
112# [ID 20020425.012] from Dave Steiner <steiner@bakerst.rutgers.edu>
113# This goes segv on 5.7.3
114use warnings 'closed' ;
115my $fh = *STDOUT{IO};
116close STDOUT or die "Can't close STDOUT";
117print $fh "Shouldn't print anything, but shouldn't SEGV either\n";
118EXPECT
119print() on closed filehandle at - line 7.
120########
f62cb720
RGS
121# pp_hot.c [pp_print]
122package foo;
123use warnings 'closed';
124open my $fh1, "nonexistent";
125print $fh1 42;
126open $fh2, "nonexistent";
127print $fh2 42;
128open $bar::fh3, "nonexistent";
129print $bar::fh3 42;
130open bar::FH4, "nonexistent";
131print bar::FH4 42;
132EXPECT
133print() on closed filehandle $fh1 at - line 5.
134print() on closed filehandle $fh2 at - line 7.
135print() on closed filehandle $fh3 at - line 9.
136print() on closed filehandle FH4 at - line 11.
137########
767a6a26 138# pp_hot.c [pp_rv2av]
4438c4b7 139use warnings 'uninitialized' ;
599cee73 140my $a = undef ;
0453d815 141my @b = @$a;
4438c4b7 142no warnings 'uninitialized' ;
0453d815 143my @c = @$a;
599cee73 144EXPECT
29489e7c 145Use of uninitialized value $a in array dereference at - line 4.
599cee73 146########
767a6a26 147# pp_hot.c [pp_rv2hv]
4438c4b7 148use warnings 'uninitialized' ;
599cee73 149my $a = undef ;
0453d815 150my %b = %$a;
4438c4b7 151no warnings 'uninitialized' ;
0453d815 152my %c = %$a;
599cee73 153EXPECT
29489e7c 154Use of uninitialized value $a in hash dereference at - line 4.
599cee73 155########
767a6a26 156# pp_hot.c [pp_aassign]
e476b1b5 157use warnings 'misc' ;
599cee73 158my %X ; %X = (1,2,3) ;
e476b1b5 159no warnings 'misc' ;
0453d815 160my %Y ; %Y = (1,2,3) ;
599cee73
PM
161EXPECT
162Odd number of elements in hash assignment at - line 3.
163########
767a6a26 164# pp_hot.c [pp_aassign]
e476b1b5 165use warnings 'misc' ;
599cee73 166my %X ; %X = [1 .. 3] ;
e476b1b5 167no warnings 'misc' ;
0453d815 168my %Y ; %Y = [1 .. 3] ;
599cee73
PM
169EXPECT
170Reference found where even-sized list expected at - line 3.
171########
767a6a26 172# pp_hot.c [Perl_do_readline]
4438c4b7 173use warnings 'closed' ;
69282e91
GS
174close STDIN ; $a = <STDIN> ;
175opendir STDIN, "." ; $a = <STDIN> ;
176closedir STDIN;
4438c4b7 177no warnings 'closed' ;
69282e91 178opendir STDIN, "." ; $a = <STDIN> ;
0453d815 179$a = <STDIN> ;
599cee73 180EXPECT
43693395
GS
181readline() on closed filehandle STDIN at - line 3.
182readline() on closed filehandle STDIN at - line 4.
183 (Are you trying to call readline() on dirhandle STDIN?)
599cee73 184########
767a6a26
PM
185# pp_hot.c [Perl_do_readline]
186use warnings 'io' ;
187my $file = "./xcv" ; unlink $file ;
977289e4 188open (FH, ">$file") or die $! ;
767a6a26
PM
189my $a = <FH> ;
190no warnings 'io' ;
191$a = <FH> ;
977289e4
NC
192use warnings 'io' ;
193open(FOO, ">&FH") or die $! ;
194$a = <FOO> ;
195no warnings 'io' ;
196$a = <FOO> ;
197use warnings 'io' ;
198$a = <FOO> ;
199$a = <FH> ;
200close (FH) or die $! ;
201close (FOO) or die $! ;
767a6a26
PM
202unlink $file ;
203EXPECT
43693395 204Filehandle FH opened only for output at - line 5.
977289e4
NC
205Filehandle FOO opened only for output at - line 10.
206Filehandle FOO opened only for output at - line 14.
207Filehandle FH opened only for output at - line 15.
767a6a26
PM
208########
209# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 210use warnings 'recursion' ;
599cee73
PM
211sub fred
212{
213 fred() if $a++ < 200
214}
4a925ff6
GS
215{
216 local $SIG{__WARN__} = sub {
217 die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
218 };
219 fred();
220}
599cee73 221EXPECT
4a925ff6 222ok
599cee73 223########
767a6a26 224# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 225no warnings 'recursion' ;
0453d815
PM
226sub fred
227{
228 fred() if $a++ < 200
229}
230{
231 local $SIG{__WARN__} = sub {
232 die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
233 };
234 fred();
235}
236EXPECT
237
238########
767a6a26 239# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 240use warnings 'recursion' ;
599cee73
PM
241$b = sub
242{
243 &$b if $a++ < 200
244} ;
245
246&$b ;
247EXPECT
248Deep recursion on anonymous subroutine at - line 5.
0453d815 249########
767a6a26 250# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 251no warnings 'recursion' ;
0453d815
PM
252$b = sub
253{
254 &$b if $a++ < 200
255} ;
256
257&$b ;
258EXPECT
6bc102ca
GS
259########
260# pp_hot.c [pp_concat]
8d6d96c1
HS
261use warnings 'uninitialized';
262my($x, $y);
263sub a { shift }
264a($x . "x"); # should warn once
265a($x . $y); # should warn twice
266$x .= $y; # should warn once
267$y .= $y; # should warn once
268EXPECT
29489e7c 269Use of uninitialized value $x in concatenation (.) or string at - line 5.
29489e7c 270Use of uninitialized value $x in concatenation (.) or string at - line 6.
c75ab21a 271Use of uninitialized value $y in concatenation (.) or string at - line 6.
29489e7c
DM
272Use of uninitialized value $y in concatenation (.) or string at - line 7.
273Use of uninitialized value $y in concatenation (.) or string at - line 8.
8d6d96c1 274########
d804643f
SC
275# pp_hot.c [pp_aelem]
276{
277use warnings 'misc';
278print $x[\1];
279}
280{
281no warnings 'misc';
282print $x[\1];
283}
284
285EXPECT
286OPTION regex
287Use of reference ".*" as array index at - line 4.
1f1cc344
JH
288########
289# pp_hot.c [pp_aelem]
290package Foo;use overload q("") => sub {};package main;$a = bless {}, "Foo";
291$b = {};
292{
293use warnings 'misc';
294print $x[$a];
295print $x[$b];
296}
297{
298no warnings 'misc';
299print $x[$a];
300print $x[$b];
301}
302
303EXPECT
304OPTION regex
305Use of reference ".*" as array index at - line 7.