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