This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
(perl #130335) fix numeric comparison for sort's built-in compare
[perl5.git] / t / lib / warnings / 9uninit
CommitLineData
29489e7c
DM
1DAPM 4/2004.
2
3Test the appearance of variable names in "Use of uninitialized value"
4warnings.
5
6The following ops aren't tested, mainly because they do IO or non-portable
7stuff:
8
9 send recv bind conect listen accept shutdown chdir chown chroot unlink
10 chmod utime rename link symlink readlink mkdir rmdir opendir seekdir
11 system exec kill getpgrp alarm sleep dofile require gethostbyname
12 gethostbyaddr getnetbyname getnetbyaddr getprotobyname getprotobynumber
13 getservbyname getservbyport sethostent setnetent setprotoent setservent
14 getpwnam getpwuid getgrnam getgrgid waitpid setpgrp setpriority
15 getpriority syscall dbmopen ioctl fcntl truncate getsockopt setsockopt
16 semctl semop semget msgget msgctl msgsnd msgrcv shmget shmctl shmread
17 shmwrite
18
19 ---------------------------------------------------
20
21
22__END__
23use warnings 'uninitialized';
24my ($m1, $m2, $v);
25
26$v = $m1 + 10;
27$v = 22 + $m2;
28$v = $m1 + $m2;
29EXPECT
30Use of uninitialized value $m1 in addition (+) at - line 4.
31Use of uninitialized value $m2 in addition (+) at - line 5.
32Use of uninitialized value $m2 in addition (+) at - line 6.
33Use of uninitialized value $m1 in addition (+) at - line 6.
34########
35use warnings 'uninitialized';
fef7e7a0
BF
36use utf8;
37use open qw( :utf8 :std );
38
39$v = $à1 + 10;
40$v = 22 + $a2;
41$v = $à1 + $a2;
42EXPECT
43Use of uninitialized value $à1 in addition (+) at - line 5.
44Use of uninitialized value $a2 in addition (+) at - line 6.
45Use of uninitialized value $a2 in addition (+) at - line 7.
46Use of uninitialized value $à1 in addition (+) at - line 7.
47########
48use warnings 'uninitialized';
29489e7c
DM
49my ($m1, $v);
50our ($g1, $g2);
51
52$v = $g1 + 21;
53$v = 31 + $g2;
54$v = $g1 + $g2;
55$v = $m1 + $g2;
56EXPECT
57Use of uninitialized value $g1 in addition (+) at - line 5.
58Use of uninitialized value $g2 in addition (+) at - line 6.
59Use of uninitialized value $g2 in addition (+) at - line 7.
60Use of uninitialized value $g1 in addition (+) at - line 7.
61Use of uninitialized value $g2 in addition (+) at - line 8.
62Use of uninitialized value $m1 in addition (+) at - line 8.
63########
64use warnings 'uninitialized';
65my ($m1, @ma, $v);
66
67$v = $ma[5] + 45;
68$v = 56 + $ma[6];
69$v = $ma[7] + $m1;
70$v = $ma[8] + $ma[9];
71$v = $ma[-1] + $ma[-2];
72EXPECT
73Use of uninitialized value $ma[5] in addition (+) at - line 4.
74Use of uninitialized value $ma[6] in addition (+) at - line 5.
75Use of uninitialized value $m1 in addition (+) at - line 6.
76Use of uninitialized value in addition (+) at - line 6.
77Use of uninitialized value in addition (+) at - line 7.
78Use of uninitialized value in addition (+) at - line 7.
79Use of uninitialized value in addition (+) at - line 8.
80Use of uninitialized value in addition (+) at - line 8.
81########
82use warnings 'uninitialized';
83my ($v);
84my @mau = (undef) x 258;
85my %mhu = ('foo', undef, 'bar', undef);
86
87$v = $mau[5] + 23;
88$v = $mau[-5] + 45;
89$v = 56 + $mau[6];
90$v = 78 + $mau[-6];
91$v = $mau[7] + $mau[8];
92$v = $mau[256] + $mau[257];
93$v = $mau[-1] + $mau[-2];
94$v = $mhu{foo} + $mhu{bar};
95EXPECT
96Use of uninitialized value $mau[5] in addition (+) at - line 6.
97Use of uninitialized value $mau[-5] in addition (+) at - line 7.
98Use of uninitialized value $mau[6] in addition (+) at - line 8.
99Use of uninitialized value $mau[-6] in addition (+) at - line 9.
100Use of uninitialized value $mau[8] in addition (+) at - line 10.
101Use of uninitialized value $mau[7] in addition (+) at - line 10.
102Use of uninitialized value $mau[257] in addition (+) at - line 11.
103Use of uninitialized value $mau[256] in addition (+) at - line 11.
104Use of uninitialized value $mau[-2] in addition (+) at - line 12.
105Use of uninitialized value $mau[-1] in addition (+) at - line 12.
106Use of uninitialized value $mhu{"bar"} in addition (+) at - line 13.
107Use of uninitialized value $mhu{"foo"} in addition (+) at - line 13.
108########
109use warnings 'uninitialized';
110my ($v);
111our (@ga);
112
113$v = $ga[8] + 21;
114$v = $ga[-8] + 46;
115$v = 57 + $ga[9];
116$v = 58 + $ga[-9];
117$v = $ga[10] + $ga[11];
118$v = $ga[-10] + $ga[-11];
119EXPECT
120Use of uninitialized value $ga[8] in addition (+) at - line 5.
121Use of uninitialized value $ga[-8] in addition (+) at - line 6.
122Use of uninitialized value $ga[9] in addition (+) at - line 7.
123Use of uninitialized value $ga[-9] in addition (+) at - line 8.
124Use of uninitialized value in addition (+) at - line 9.
125Use of uninitialized value in addition (+) at - line 9.
126Use of uninitialized value in addition (+) at - line 10.
127Use of uninitialized value in addition (+) at - line 10.
128########
129use warnings 'uninitialized';
130my ($v);
131our @gau = (undef) x 258;
132our %ghu = ('foo', undef, 'bar', undef);
133
134$v = $gau[8] + 46;
135$v = $gau[-8] + 47;
136$v = 57 + $gau[9];
137$v = 57 + $gau[-9];
138$v = $gau[10] + $gau[11];
139$v = $gau[256] + $gau[257];
140$v = $gau[-1] + $gau[-2];
141$v = $ghu{foo} + $ghu{bar};
142EXPECT
143Use of uninitialized value $gau[8] in addition (+) at - line 6.
144Use of uninitialized value $gau[-8] in addition (+) at - line 7.
145Use of uninitialized value $gau[9] in addition (+) at - line 8.
146Use of uninitialized value $gau[-9] in addition (+) at - line 9.
147Use of uninitialized value $gau[11] in addition (+) at - line 10.
148Use of uninitialized value $gau[10] in addition (+) at - line 10.
149Use of uninitialized value $gau[257] in addition (+) at - line 11.
150Use of uninitialized value $gau[256] in addition (+) at - line 11.
151Use of uninitialized value $gau[-2] in addition (+) at - line 12.
152Use of uninitialized value $gau[-1] in addition (+) at - line 12.
153Use of uninitialized value $ghu{"bar"} in addition (+) at - line 13.
154Use of uninitialized value $ghu{"foo"} in addition (+) at - line 13.
155########
156use warnings 'uninitialized';
157my ($v);
158our @gau = (undef) x 258;
159our %ghu = ('foo', undef, 'bar', undef);
160my @mau = (undef) x 258;
161my %mhu = ('foo', undef, 'bar', undef);
162
163my $i1 = 10;
164my $i2 = 20;
165my $i3 = 2000;
166my $k1 = 'foo';
167my $k2 = 'bar';
168my $k3 = 'baz';
169$v = $mau[$i1] + $mau[$i2];
170$v = $gau[$i1] + $gau[$i2];
171$v = $gau[$i1] + $gau[$i3];
172$v = $mhu{$k1} + $mhu{$k2};
173$v = $ghu{$k1} + $ghu{$k2};
174$v = $ghu{$k1} + $ghu{$k3};
175EXPECT
176Use of uninitialized value $mau[20] in addition (+) at - line 14.
177Use of uninitialized value $mau[10] in addition (+) at - line 14.
178Use of uninitialized value $gau[20] in addition (+) at - line 15.
179Use of uninitialized value $gau[10] in addition (+) at - line 15.
180Use of uninitialized value in addition (+) at - line 16.
181Use of uninitialized value $gau[10] in addition (+) at - line 16.
182Use of uninitialized value $mhu{"bar"} in addition (+) at - line 17.
183Use of uninitialized value $mhu{"foo"} in addition (+) at - line 17.
184Use of uninitialized value $ghu{"bar"} in addition (+) at - line 18.
185Use of uninitialized value $ghu{"foo"} in addition (+) at - line 18.
186Use of uninitialized value in addition (+) at - line 19.
187Use of uninitialized value $ghu{"foo"} in addition (+) at - line 19.
188########
189use warnings 'uninitialized';
190my ($m1, $m2, @ma, %mh, $v);
191our ($g1, $g2, @ga, %gh);
192
193$v = $ma[$m1];
194$v = $ma[$g1];
195$v = $ga[$m2];
196$v = $ga[$g2];
197
198$v = $mh{$m1};
199$v = $mh{$g1};
200$v = $gh{$m2};
201$v = $gh{$g2};
202
203$v = $m1+($m2-$g1);
204$v = $ma[$ga[3]];
205$v = $ga[$ma[4]];
206EXPECT
207Use of uninitialized value $m1 in array element at - line 5.
208Use of uninitialized value $g1 in array element at - line 6.
209Use of uninitialized value $m2 in array element at - line 7.
210Use of uninitialized value $g2 in array element at - line 8.
211Use of uninitialized value $m1 in hash element at - line 10.
212Use of uninitialized value $g1 in hash element at - line 11.
213Use of uninitialized value $m2 in hash element at - line 12.
214Use of uninitialized value $g2 in hash element at - line 13.
215Use of uninitialized value $g1 in subtraction (-) at - line 15.
216Use of uninitialized value $m2 in subtraction (-) at - line 15.
217Use of uninitialized value $m1 in addition (+) at - line 15.
218Use of uninitialized value $ga[3] in array element at - line 16.
219Use of uninitialized value $ma[4] in array element at - line 17.
220########
221use warnings 'uninitialized';
222my (@ma, %mh, $v);
223our (@ga, %gh);
224
225$v = sin $ga[1000];
226$v = sin $ma[1000];
227$v = sin $gh{foo};
228$v = sin $mh{bar};
229
230$v = sin $ga[$$];
231$v = sin $ma[$$];
232$v = sin $gh{$$};
233$v = sin $mh{$$};
234EXPECT
235Use of uninitialized value $ga[1000] in sin at - line 5.
236Use of uninitialized value $ma[1000] in sin at - line 6.
237Use of uninitialized value $gh{"foo"} in sin at - line 7.
238Use of uninitialized value $mh{"bar"} in sin at - line 8.
239Use of uninitialized value within @ga in sin at - line 10.
240Use of uninitialized value within @ma in sin at - line 11.
241Use of uninitialized value within %gh in sin at - line 12.
242Use of uninitialized value within %mh in sin at - line 13.
243########
244use warnings 'uninitialized';
245my (@mat, %mht, $v);
246sub X::TIEARRAY { bless [], 'X' }
247sub X::TIEHASH { bless [], 'X' }
248sub X::FETCH { undef }
249tie @mat, 'X';
250tie %mht, 'X';
251my $key1 = 'akey';
252my $key2 = 'bkey';
253my $index1 = 33;
254my $index2 = 55;
255
256$v = sin $mat[0];
257$v = $mat[0] + $mat[1];
258$v = sin $mat[1000];
259$v = $mat[1000] + $mat[1001];
260
261$v = sin $mat[$index1];
262$v = $mat[$index1] + $mat[$index2];
263
264$v = sin $mht{foo};
265$v = $mht{foo} + $mht{bar};
266
267$v = sin $mht{$key1};
268$v = $mht{$key1} + $mht{$key2};
269
270$v = $1+1;
271EXPECT
272Use of uninitialized value $mat[0] in sin at - line 13.
273Use of uninitialized value in addition (+) at - line 14.
274Use of uninitialized value in addition (+) at - line 14.
275Use of uninitialized value $mat[1000] in sin at - line 15.
276Use of uninitialized value in addition (+) at - line 16.
277Use of uninitialized value in addition (+) at - line 16.
278Use of uninitialized value within @mat in sin at - line 18.
279Use of uninitialized value in addition (+) at - line 19.
280Use of uninitialized value in addition (+) at - line 19.
281Use of uninitialized value $mht{"foo"} in sin at - line 21.
282Use of uninitialized value in addition (+) at - line 22.
283Use of uninitialized value in addition (+) at - line 22.
284Use of uninitialized value within %mht in sin at - line 24.
285Use of uninitialized value in addition (+) at - line 25.
286Use of uninitialized value in addition (+) at - line 25.
287Use of uninitialized value $1 in addition (+) at - line 27.
288########
289use warnings 'uninitialized';
290my ($m1);
291our ($g1, @ga);
292
293print $ga[1000];
294print STDERR $ga[1000];
295print STDERR $m1, $g1, $ga[1],$m2;
296print STDERR "", $ga[1],"";
297EXPECT
fa8d1836
DM
298Use of uninitialized value in print at - line 5.
299Use of uninitialized value in print at - line 6.
29489e7c
DM
300Use of uninitialized value $m1 in print at - line 7.
301Use of uninitialized value $g1 in print at - line 7.
302Use of uninitialized value in print at - line 7.
303Use of uninitialized value $m2 in print at - line 7.
fa8d1836 304Use of uninitialized value in print at - line 8.
29489e7c
DM
305########
306use warnings 'uninitialized';
307my ($m1);
308our ($g1);
309
310close $m1; # exercises rv2gv
311close $g1; # exercises rv2gv
ed996e63 312close undef; # exercises rv2gv
29489e7c
DM
313EXPECT
314Use of uninitialized value $m1 in ref-to-glob cast at - line 5.
315Use of uninitialized value $g1 in ref-to-glob cast at - line 6.
ed996e63 316Use of uninitialized value in ref-to-glob cast at - line 7.
29489e7c
DM
317########
318use warnings 'uninitialized';
319my ($m1, $m2, $v);
320our ($g1, $g2);
321
322$v = $$m1;
323$v = $$g1;
324
325$v = @$m1;
326$v = @$g1;
327$v = %$m2;
328$v = %$g2;
e21bd382
DM
329
330$v = ${"foo.bar"}+1;
331$v = ${"foo$m1"}+1;
332$v = ${"foo$g1"}+1;
29489e7c
DM
333EXPECT
334Use of uninitialized value $m1 in scalar dereference at - line 5.
335Use of uninitialized value $g1 in scalar dereference at - line 6.
336Use of uninitialized value $m1 in array dereference at - line 8.
337Use of uninitialized value $g1 in array dereference at - line 9.
338Use of uninitialized value $m2 in hash dereference at - line 10.
339Use of uninitialized value $g2 in hash dereference at - line 11.
e21bd382
DM
340Use of uninitialized value in addition (+) at - line 13.
341Use of uninitialized value $m1 in concatenation (.) or string at - line 14.
342Use of uninitialized value in addition (+) at - line 14.
343Use of uninitialized value $g1 in concatenation (.) or string at - line 15.
344Use of uninitialized value in addition (+) at - line 15.
29489e7c
DM
345########
346use warnings 'uninitialized';
347my ($m1, $v);
348our ($g1);
349
350$v = $m1 | $m2;
351$v = $m1 & $m2;
352$v = $m1 ^ $m2;
353$v = ~$m1;
354
355$v = $g1 | $g2;
356$v = $g1 & $g2;
357$v = $g1 ^ $g2;
358$v = ~$g1;
359EXPECT
360Use of uninitialized value $m1 in bitwise or (|) at - line 5.
361Use of uninitialized value $m2 in bitwise or (|) at - line 5.
362Use of uninitialized value $m1 in bitwise and (&) at - line 6.
363Use of uninitialized value $m2 in bitwise and (&) at - line 6.
364Use of uninitialized value $m1 in bitwise xor (^) at - line 7.
365Use of uninitialized value $m2 in bitwise xor (^) at - line 7.
366Use of uninitialized value $m1 in 1's complement (~) at - line 8.
367Use of uninitialized value $g1 in bitwise or (|) at - line 10.
368Use of uninitialized value $g2 in bitwise or (|) at - line 10.
369Use of uninitialized value $g1 in bitwise and (&) at - line 11.
370Use of uninitialized value $g2 in bitwise and (&) at - line 11.
371Use of uninitialized value $g1 in bitwise xor (^) at - line 12.
372Use of uninitialized value $g2 in bitwise xor (^) at - line 12.
373Use of uninitialized value $g1 in 1's complement (~) at - line 13.
374########
375use warnings 'uninitialized';
376my ($v);
377
378my $tmp1; $v = $tmp1++; # (doesn't warn)
379our $tmp2; $v = $tmp2++; # (doesn't warn)
380my $tmp3; $v = ++$tmp1; # (doesn't warn)
381our $tmp4; $v = ++$tmp2; # (doesn't warn)
382
383my $tmp5; $v = $tmp5--; # (doesn't warn)
384our $tmp6; $v = $tmp6--; # (doesn't warn)
385my $tmp7; $v = --$tmp7; # (doesn't warn)
386our $tmp8; $v = --$tmp8; # (doesn't warn)
387EXPECT
388########
389use warnings 'uninitialized';
390
391my $s1; chomp $s1;
392my $s2; chop $s2;
393my ($s3,$s4); chomp ($s3,$s4);
394my ($s5,$s6); chop ($s5,$s6);
395EXPECT
396Use of uninitialized value $s1 in scalar chomp at - line 3.
397Use of uninitialized value $s2 in scalar chop at - line 4.
29489e7c 398Use of uninitialized value $s3 in chomp at - line 5.
20cf1f79 399Use of uninitialized value $s4 in chomp at - line 5.
29489e7c
DM
400Use of uninitialized value $s5 in chop at - line 6.
401Use of uninitialized value $s6 in chop at - line 6.
402########
403use warnings 'uninitialized';
404my ($m1);
405
406local $/ =\$m1;
407my $x = "abc";
408chomp $x; chop $x;
409my $y;
410chomp ($x, $y); chop ($x, $y);
411EXPECT
b3a2acfa
YO
412Use of uninitialized value $m1 in scalar assignment at - line 4.
413Use of uninitialized value $m1 in scalar assignment at - line 4.
414Setting $/ to a reference to zero as a form of slurp is deprecated, treating as undef at - line 4.
29489e7c
DM
415Use of uninitialized value $y in chop at - line 8.
416########
417use warnings 'uninitialized';
418my ($m1, @ma, %mh);
419our ($g1);
420
421delete $ma[$m1];
422delete @ma[$m1, $g1];
423delete $mh{$m1};
424delete @mh{$m1, $g1};
425EXPECT
426Use of uninitialized value $m1 in delete at - line 5.
427Use of uninitialized value $m1 in delete at - line 6.
428Use of uninitialized value $g1 in delete at - line 6.
429Use of uninitialized value $m1 in delete at - line 7.
430Use of uninitialized value $m1 in delete at - line 8.
431Use of uninitialized value $g1 in delete at - line 8.
432########
433use warnings 'uninitialized';
434my ($m1, @ma, %mh);
435our ($g1);
436
437my @a = @ma[$m1, $g1];
438@a = (4,5)[$m1, $g1];
439@a = @mh{$m1, $g1};
440EXPECT
441Use of uninitialized value $m1 in array slice at - line 5.
442Use of uninitialized value $g1 in array slice at - line 5.
443Use of uninitialized value $m1 in list slice at - line 6.
444Use of uninitialized value $g1 in list slice at - line 6.
445Use of uninitialized value $m1 in hash slice at - line 7.
446Use of uninitialized value $g1 in hash slice at - line 7.
447########
448use warnings 'uninitialized';
449my ($m1, @ma, %mh, $v);
450our ($g1, @ga, %gh);
451
452$v = exists $ma[$m1];
453$v = exists $ga[$g1];
454$v = exists $mh{$m1};
455$v = exists $gh{$g1};
456EXPECT
457Use of uninitialized value $m1 in exists at - line 5.
458Use of uninitialized value $g1 in exists at - line 6.
459Use of uninitialized value $m1 in exists at - line 7.
460Use of uninitialized value $g1 in exists at - line 8.
461########
462use warnings 'uninitialized';
4f187fc9
VP
463my ($m1, $m2);
464my ($v, @a);
93398190 465my ($t, $u) = (1, 1);
4f187fc9
VP
466
467local $.;
468
93398190
VP
469@ma = (1 .. 2);
470@ma = ($t .. 2);
4f187fc9 471@ma = ($m1 .. 2);
93398190
VP
472@ma = (1 .. $u);
473@ma = (1 .. $m2);
474
475@ma = (1 ... 2);
476@ma = ($t ... 2);
477@ma = ($m1 ... 2);
478@ma = (1 ... $u);
479@ma = (1 ... $m2);
4f187fc9 480
93398190
VP
481$v = (1 .. 2);
482$v = ($t .. 2);
4f187fc9 483$v = ($m1 .. 2);
93398190
VP
484$v = (1 .. $u);
485$v = (1 .. $m2);
486
487$v = (1 ... 2);
488$v = ($t ... 2);
489$v = ($m1 ... 2);
490$v = (1 ... $u);
491$v = (1 ... $m2);
492EXPECT
493Use of uninitialized value $m1 in range (or flop) at - line 10.
494Use of uninitialized value $m2 in range (or flop) at - line 12.
495Use of uninitialized value $m1 in range (or flop) at - line 16.
496Use of uninitialized value $m2 in range (or flop) at - line 18.
497Use of uninitialized value $. in range (or flip) at - line 20.
498Use of uninitialized value $. in range (or flop) at - line 21.
499Use of uninitialized value $. in range (or flip) at - line 23.
500Use of uninitialized value $. in range (or flip) at - line 24.
501Use of uninitialized value $. in range (or flip) at - line 26.
502Use of uninitialized value $. in range (or flip) at - line 29.
503Use of uninitialized value $. in range (or flip) at - line 30.
504########
505use warnings 'uninitialized';
506my ($m1, $m2);
507my ($v, @a);
508my ($t, $u) = (1, 1);
509
510@ma = ($t .. $u);
511@ma = ($m1 .. $u);
512@ma = ($t .. $m2);
513@ma = ($m1 .. $m2);
514
515@ma = ($t ... $u);
516@ma = ($m1 ... $u);
517@ma = ($t ... $m2);
518@ma = ($m1 ... $m2);
519
520$v = ($t .. $u);
521$v = ($m1 .. $u);
522$v = ($t .. $m2);
4f187fc9 523$v = ($m1 .. $m2);
93398190
VP
524
525$v = ($t ... $u);
526$v = ($m1 ... $u);
527$v = ($t ... $m2);
528$v = ($m1 ... $m2);
4f187fc9 529EXPECT
93398190
VP
530Use of uninitialized value $m1 in range (or flop) at - line 7.
531Use of uninitialized value $m2 in range (or flop) at - line 8.
3c323193 532Use of uninitialized value $m1 in range (or flop) at - line 9.
c774086b 533Use of uninitialized value $m2 in range (or flop) at - line 9.
93398190
VP
534Use of uninitialized value $m1 in range (or flop) at - line 12.
535Use of uninitialized value $m2 in range (or flop) at - line 13.
3c323193 536Use of uninitialized value $m1 in range (or flop) at - line 14.
c774086b 537Use of uninitialized value $m2 in range (or flop) at - line 14.
4f187fc9
VP
538########
539use warnings 'uninitialized';
29489e7c
DM
540my ($m1, $v);
541our ($g1);
542
543my ($x1,$x2);
544$v = $x1 << $m1;
545$v = $x2 << $g1;
546EXPECT
547Use of uninitialized value $m1 in left bitshift (<<) at - line 6.
548Use of uninitialized value $x1 in left bitshift (<<) at - line 6.
549Use of uninitialized value $g1 in left bitshift (<<) at - line 7.
550Use of uninitialized value $x2 in left bitshift (<<) at - line 7.
551########
552use warnings 'uninitialized';
553my ($m1, $m2, $v);
554our ($g1, $g2);
555
556use integer;
557$v = $m1 + $g1;
558$v = $m1 - $g1;
559$v = $m1 * $g1;
560eval {$v = $m1 / $g1};
561$v = $m2 / 2;
562eval {$v = $m1 % $g1};
563$v = $m2 % 2;
564$v = $m1 < $g1;
565$v = $m1 > $g1;
566$v = $m1 <= $g1;
567$v = $m1 >= $g1;
568$v = $m1 == $g1;
569$v = $m1 != $g1;
570$v = $m1 <=> $g1;
571$v = -$m1;
572EXPECT
e62ca0f9 573Use of uninitialized value $g1 in integer addition (+) at - line 6.
096c060c 574Use of uninitialized value $m1 in integer addition (+) at - line 6.
e62ca0f9 575Use of uninitialized value $g1 in integer subtraction (-) at - line 7.
096c060c 576Use of uninitialized value $m1 in integer subtraction (-) at - line 7.
96b6b87f 577Use of uninitialized value $g1 in integer multiplication (*) at - line 8.
096c060c 578Use of uninitialized value $m1 in integer multiplication (*) at - line 8.
29489e7c
DM
579Use of uninitialized value $g1 in integer division (/) at - line 9.
580Use of uninitialized value $m2 in integer division (/) at - line 10.
96b6b87f 581Use of uninitialized value $g1 in integer modulus (%) at - line 11.
096c060c 582Use of uninitialized value $m1 in integer modulus (%) at - line 11.
29489e7c 583Use of uninitialized value $m2 in integer modulus (%) at - line 12.
9b029393 584Use of uninitialized value $g1 in integer lt (<) at - line 13.
096c060c 585Use of uninitialized value $m1 in integer lt (<) at - line 13.
fd2dbd2b 586Use of uninitialized value $g1 in integer gt (>) at - line 14.
096c060c 587Use of uninitialized value $m1 in integer gt (>) at - line 14.
5c7d20ff 588Use of uninitialized value $g1 in integer le (<=) at - line 15.
096c060c 589Use of uninitialized value $m1 in integer le (<=) at - line 15.
f2bd3a8b 590Use of uninitialized value $g1 in integer ge (>=) at - line 16.
096c060c 591Use of uninitialized value $m1 in integer ge (>=) at - line 16.
bfa9dccd 592Use of uninitialized value $g1 in integer eq (==) at - line 17.
096c060c 593Use of uninitialized value $m1 in integer eq (==) at - line 17.
577914ca 594Use of uninitialized value $g1 in integer ne (!=) at - line 18.
096c060c 595Use of uninitialized value $m1 in integer ne (!=) at - line 18.
4cdd48d8 596Use of uninitialized value $g1 in integer comparison (<=>) at - line 19.
096c060c 597Use of uninitialized value $m1 in integer comparison (<=>) at - line 19.
29489e7c
DM
598Use of uninitialized value $m1 in integer negation (-) at - line 20.
599########
600use warnings 'uninitialized';
601my ($m1, $m2, $v);
602our ($g1, $g2);
603
604$v = int($g1);
605$v = abs($g2);
606EXPECT
607Use of uninitialized value $g1 in int at - line 5.
29489e7c
DM
608Use of uninitialized value $g2 in abs at - line 6.
609########
610use warnings 'uninitialized';
611my ($m1, $m2, $v);
612our ($g1);
613
614$v = pack $m1;
615$v = pack "i*", $m2, $g1, $g2;
616my @unpack = unpack $m1, $m2;
617EXPECT
618Use of uninitialized value $m1 in pack at - line 5.
619Use of uninitialized value $m2 in pack at - line 6.
620Use of uninitialized value $g1 in pack at - line 6.
621Use of uninitialized value $g2 in pack at - line 6.
622Use of uninitialized value $m1 in unpack at - line 7.
623Use of uninitialized value $m2 in unpack at - line 7.
624########
625use warnings 'uninitialized';
626my ($m1);
627our ($g1);
628
629my @sort;
630@sort = sort $m1, $g1;
631@sort = sort {$a <=> $b} $m1, $g1;
632sub sortf {$a-1 <=> $b-1};
633@sort = sort &sortf, $m1, $g1;
d4c6760a
FC
634@sort = sort { undef } 1, 2;
635sub frobnicate($$) { undef }
636@sort = sort frobnicate 1, 2;
a9ea019a
FC
637@sort = sort pyfg 1, 2;
638@sort = sort pyfgc 1, 2;
639no warnings;
640sub pyfg { undef }
641sub pyfgc($$) { undef }
1715fa64
FC
642use warnings;
643sub dog {}
644sub dogwood($$) {}
645@sort = sort dog 1,2;
646@sort = sort dogwood 1,2;
29489e7c
DM
647EXPECT
648Use of uninitialized value $m1 in sort at - line 6.
649Use of uninitialized value $g1 in sort at - line 6.
650Use of uninitialized value $m1 in sort at - line 6.
651Use of uninitialized value $g1 in sort at - line 6.
652Use of uninitialized value $m1 in sort at - line 7.
653Use of uninitialized value $g1 in sort at - line 7.
29489e7c 654Use of uninitialized value $g1 in sort at - line 7.
427fbfe8 655Use of uninitialized value $m1 in sort at - line 7.
29489e7c
DM
656Use of uninitialized value $a in subtraction (-) at - line 8.
657Use of uninitialized value $b in subtraction (-) at - line 8.
658Use of uninitialized value $m1 in sort at - line 9.
659Use of uninitialized value $g1 in sort at - line 9.
660Use of uninitialized value $m1 in sort at - line 9.
661Use of uninitialized value $m1 in sort at - line 9.
662Use of uninitialized value $g1 in sort at - line 9.
663Use of uninitialized value $g1 in sort at - line 9.
d4c6760a 664Use of uninitialized value in sort at - line 10.
a9ea019a
FC
665Use of uninitialized value in sort at - line 12.
666Use of uninitialized value in sort at - line 13.
667Use of uninitialized value in sort at - line 14.
1715fa64
FC
668Use of uninitialized value in sort at - line 21.
669Use of uninitialized value in sort at - line 22.
29489e7c 670########
b41db0e2 671use Config;
85272d31 672unless ($Config{d_double_has_inf} && $Config{d_double_has_nan}) {
b41db0e2
JH
673 print <<EOM ;
674SKIPPED
059d8568 675# No inf/nan support
b41db0e2
JH
676EOM
677 exit ;
678}
679my $nan = eval 'sin 9**9**9';
f3dab52a
FC
680if ($nan == $nan) {
681 print <<EOM ;
682SKIPPED
683# No nan support
684EOM
685 exit ;
686}
687use warnings 'uninitialized';
688# The optimised {$a<=>$b} case should behave the same way as unoptimised.
689@sort = sort { ($a)[0] <=> $b } 1, $nan;
690@sort = sort { $a <=> $b } 1, $nan;
691EXPECT
85272d31
JH
692Use of uninitialized value in sort at - line 19.
693Use of uninitialized value in sort at - line 20.
f3dab52a 694########
29489e7c
DM
695use warnings 'uninitialized';
696my ($m1, $m2, $v);
697our ($g1);
698
699eval { $v = $m1 / $g1 };
700$v = $m2 / 2;
701eval { $v = $m1 % $g1 };
702$v = $m2 % 2;
703$v = $m1 == $g1;
704$v = $m1 >= $g1;
705$v = $m1 > $g1;
706$v = $m1 <= $g1;
707$v = $m1 < $g1;
708$v = $m1 * $g1;
709$v = $m1 <=>$g1;
710$v = $m1 != $g1;
711$v = $m1 -$g1;
712$v = $m1 ** $g1;
713$v = $m1 + $g1;
714$v = $m1 - $g1;
715EXPECT
716Use of uninitialized value $g1 in division (/) at - line 5.
717Use of uninitialized value $m1 in division (/) at - line 5.
718Use of uninitialized value $m2 in division (/) at - line 6.
719Use of uninitialized value $g1 in modulus (%) at - line 7.
720Use of uninitialized value $m1 in modulus (%) at - line 7.
721Use of uninitialized value $m2 in modulus (%) at - line 8.
722Use of uninitialized value $g1 in numeric eq (==) at - line 9.
723Use of uninitialized value $m1 in numeric eq (==) at - line 9.
724Use of uninitialized value $g1 in numeric ge (>=) at - line 10.
725Use of uninitialized value $m1 in numeric ge (>=) at - line 10.
726Use of uninitialized value $g1 in numeric gt (>) at - line 11.
727Use of uninitialized value $m1 in numeric gt (>) at - line 11.
728Use of uninitialized value $g1 in numeric le (<=) at - line 12.
729Use of uninitialized value $m1 in numeric le (<=) at - line 12.
730Use of uninitialized value $g1 in numeric lt (<) at - line 13.
731Use of uninitialized value $m1 in numeric lt (<) at - line 13.
732Use of uninitialized value $g1 in multiplication (*) at - line 14.
733Use of uninitialized value $m1 in multiplication (*) at - line 14.
734Use of uninitialized value $g1 in numeric comparison (<=>) at - line 15.
735Use of uninitialized value $m1 in numeric comparison (<=>) at - line 15.
736Use of uninitialized value $g1 in numeric ne (!=) at - line 16.
737Use of uninitialized value $m1 in numeric ne (!=) at - line 16.
738Use of uninitialized value $g1 in subtraction (-) at - line 17.
739Use of uninitialized value $m1 in subtraction (-) at - line 17.
740Use of uninitialized value $g1 in exponentiation (**) at - line 18.
741Use of uninitialized value $m1 in exponentiation (**) at - line 18.
742Use of uninitialized value $g1 in addition (+) at - line 19.
743Use of uninitialized value $m1 in addition (+) at - line 19.
744Use of uninitialized value $g1 in subtraction (-) at - line 20.
745Use of uninitialized value $m1 in subtraction (-) at - line 20.
746########
747use warnings 'uninitialized';
4c3ac4ba
FC
748sub TIESCALAR{bless[]}
749sub FETCH { undef }
750
751tie my $m1, "";
7d779b23
FC
752my $v;
753$v = $m1 + $m1;
754$v = $m1 - $m1;
837c8798
FC
755no warnings;
756$v = $m1 + $m1;
7d779b23 757$v = $m1 - $m1;
4c3ac4ba 758EXPECT
7d779b23
FC
759Use of uninitialized value $m1 in addition (+) at - line 7.
760Use of uninitialized value $m1 in addition (+) at - line 7.
761Use of uninitialized value $m1 in subtraction (-) at - line 8.
762Use of uninitialized value $m1 in subtraction (-) at - line 8.
4c3ac4ba
FC
763########
764use warnings 'uninitialized';
29489e7c
DM
765my ($m1, $v);
766our ($g1);
767
768$v = *global1{$m1};
769$v = prototype $g1;
770$v = bless [], $g1;
771$v = `$m1`;
772
773$v = $m1 . $g1;
774EXPECT
775Use of uninitialized value $m1 in glob elem at - line 5.
776Use of uninitialized value $g1 in subroutine prototype at - line 6.
777Use of uninitialized value $g1 in bless at - line 7.
778Use of uninitialized value $m1 in quoted execution (``, qx) at - line 8.
29489e7c 779Use of uninitialized value $m1 in concatenation (.) or string at - line 10.
c75ab21a 780Use of uninitialized value $g1 in concatenation (.) or string at - line 10.
29489e7c
DM
781########
782use warnings 'uninitialized';
783my ($m1);
784our ($g1, $g2);
785
786/y/;
787/$m1/;
788/$g1/;
789
790s/y/z/; undef $_;
791s/$m1/z/; undef $_;
792s//$g1/; undef $_;
793s/$m1/$g1/; undef $_;
794tr/x/y/; undef $_;
290797f7 795tr/x/y/r; undef $_;
29489e7c 796
29489e7c
DM
797$g2 =~ /y/;
798$g2 =~ /$m1/;
799$g2 =~ /$g1/;
800$g2 =~ s/y/z/; undef $g2;
801$g2 =~ s/$m1/z/; undef $g2;
802$g2 =~ s//$g1/; undef $g2;
803$g2 =~ s/$m1/$g1/; undef $g2;
804$g2 =~ tr/x/y/; undef $g2; # XXX can't extract var name yet
290797f7 805$g2 =~ tr/x/y/r; undef $g2; # XXX can't extract var name yet
29489e7c
DM
806
807my $foo = "abc";
808$foo =~ /$m1/;
809$foo =~ /$g1/;
810$foo =~ s/y/z/;
811$foo =~ s/$m1/z/;
812$foo =~ s//$g1/;
813$foo =~ s/$m1/$g1/;
814$foo =~ s/./$m1/e;
50edf520
DM
815undef $g1;
816$m1 = '$g1';
817$foo =~ s//$m1/ee;
05a502dc
FC
818undef $m1;
819$m1 =~ tr/x/y/; undef $m1;
820$m1 =~ tr/x/y/r;
29489e7c
DM
821EXPECT
822Use of uninitialized value $_ in pattern match (m//) at - line 5.
823Use of uninitialized value $m1 in regexp compilation at - line 6.
824Use of uninitialized value $_ in pattern match (m//) at - line 6.
825Use of uninitialized value $g1 in regexp compilation at - line 7.
826Use of uninitialized value $_ in pattern match (m//) at - line 7.
827Use of uninitialized value $_ in substitution (s///) at - line 9.
828Use of uninitialized value $m1 in regexp compilation at - line 10.
829Use of uninitialized value $_ in substitution (s///) at - line 10.
830Use of uninitialized value $_ in substitution (s///) at - line 10.
831Use of uninitialized value $_ in substitution (s///) at - line 11.
29489e7c 832Use of uninitialized value $_ in substitution (s///) at - line 11.
b97b7b69 833Use of uninitialized value $g1 in substitution iterator at - line 11.
29489e7c
DM
834Use of uninitialized value $m1 in regexp compilation at - line 12.
835Use of uninitialized value $_ in substitution (s///) at - line 12.
836Use of uninitialized value $_ in substitution (s///) at - line 12.
837Use of uninitialized value $g1 in substitution iterator at - line 12.
838Use of uninitialized value $_ in transliteration (tr///) at - line 13.
290797f7 839Use of uninitialized value $_ in transliteration (tr///) at - line 14.
7fba2966
FC
840Use of uninitialized value $g2 in pattern match (m//) at - line 16.
841Use of uninitialized value $m1 in regexp compilation at - line 17.
842Use of uninitialized value $g2 in pattern match (m//) at - line 17.
843Use of uninitialized value $g1 in regexp compilation at - line 18.
844Use of uninitialized value $g2 in pattern match (m//) at - line 18.
845Use of uninitialized value $g2 in substitution (s///) at - line 19.
846Use of uninitialized value $m1 in regexp compilation at - line 20.
847Use of uninitialized value $g2 in substitution (s///) at - line 20.
848Use of uninitialized value $g2 in substitution (s///) at - line 20.
849Use of uninitialized value $g2 in substitution (s///) at - line 21.
850Use of uninitialized value $g2 in substitution (s///) at - line 21.
851Use of uninitialized value $g1 in substitution iterator at - line 21.
852Use of uninitialized value $m1 in regexp compilation at - line 22.
853Use of uninitialized value $g2 in substitution (s///) at - line 22.
854Use of uninitialized value $g2 in substitution (s///) at - line 22.
b97b7b69 855Use of uninitialized value $g1 in substitution iterator at - line 22.
7fba2966
FC
856Use of uninitialized value in transliteration (tr///) at - line 23.
857Use of uninitialized value in transliteration (tr///) at - line 24.
858Use of uninitialized value $m1 in regexp compilation at - line 27.
859Use of uninitialized value $g1 in regexp compilation at - line 28.
860Use of uninitialized value $m1 in regexp compilation at - line 30.
861Use of uninitialized value $g1 in substitution iterator at - line 31.
862Use of uninitialized value $m1 in regexp compilation at - line 32.
b97b7b69 863Use of uninitialized value $g1 in substitution iterator at - line 32.
7fba2966
FC
864Use of uninitialized value $m1 in substitution (s///) at - line 33.
865Use of uninitialized value in substitution iterator at - line 36.
866Use of uninitialized value $m1 in transliteration (tr///) at - line 38.
867Use of uninitialized value $m1 in transliteration (tr///) at - line 39.
29489e7c
DM
868########
869use warnings 'uninitialized';
870my ($m1);
871
872{ my $foo = "abc"; (substr($foo,0,0)) = ($m1) }
873EXPECT
874Use of uninitialized value $m1 in list assignment at - line 4.
875########
876use warnings 'uninitialized';
877our ($g1);
878
879study;
880study $g1;
881EXPECT
882Use of uninitialized value $_ in study at - line 4.
883Use of uninitialized value $g1 in study at - line 5.
884########
885use warnings 'uninitialized';
886my ($m1);
887
888pos()=0;
889pos($m1)=0;
890EXPECT
891Use of uninitialized value $_ in scalar assignment at - line 4.
892Use of uninitialized value $m1 in scalar assignment at - line 5.
893########
894use warnings 'uninitialized';
895my ($m1);
cc4b8646
DM
896our ($g1);
897
898$v = pos($m1) + 1;
899$v = pos($g1) + 1;
900$m1 = 0;
901$g1 = "";
902$v = pos($m1) + 1;
903$v = pos($g1) + 1;
904EXPECT
905Use of uninitialized value in addition (+) at - line 5.
906Use of uninitialized value in addition (+) at - line 6.
907Use of uninitialized value in addition (+) at - line 9.
908Use of uninitialized value in addition (+) at - line 10.
909########
910use warnings 'uninitialized';
911my ($m1);
29489e7c
DM
912
913{ my $x = "a" x $m1 } # NB LHS of repeat does not warn
914{ my @x = ("a") x $m1 }
915EXPECT
916Use of uninitialized value $m1 in repeat (x) at - line 4.
917Use of uninitialized value $m1 in repeat (x) at - line 5.
918########
919use warnings 'uninitialized';
920my ($m1, $v);
921our ($g1);
922
923$v = "$m1";
924
925$v = $m1 lt $g1;
926$v = $m1 le $g1;
927$v = $m1 gt $g1;
928$v = $m1 ge $g1;
929$v = $m1 eq $g1;
930$v = $m1 ne $g1;
931$v = $m1 cmp $g1;
932EXPECT
933Use of uninitialized value $m1 in string at - line 5.
934Use of uninitialized value $m1 in string lt at - line 7.
935Use of uninitialized value $g1 in string lt at - line 7.
936Use of uninitialized value $m1 in string le at - line 8.
937Use of uninitialized value $g1 in string le at - line 8.
938Use of uninitialized value $m1 in string gt at - line 9.
939Use of uninitialized value $g1 in string gt at - line 9.
940Use of uninitialized value $m1 in string ge at - line 10.
941Use of uninitialized value $g1 in string ge at - line 10.
942Use of uninitialized value $m1 in string eq at - line 11.
943Use of uninitialized value $g1 in string eq at - line 11.
944Use of uninitialized value $m1 in string ne at - line 12.
945Use of uninitialized value $g1 in string ne at - line 12.
946Use of uninitialized value $m1 in string comparison (cmp) at - line 13.
947Use of uninitialized value $g1 in string comparison (cmp) at - line 13.
948########
949use warnings 'uninitialized';
950my ($m1, $v);
951our ($g1);
952
953$v = atan2($m1,$g1);
954$v = sin $m1;
955$v = cos $m1;
956$v = rand $m1;
957$v = srand $m1;
958$v = exp $m1;
959$v = eval {log $m1};
960$v = sqrt $m1;
961$v = hex $m1;
962$v = oct $m1;
9f621bb0
NC
963$v = oct;
964$v = length; # does not warn
29489e7c 965EXPECT
d4b629d0 966Use of uninitialized value $g1 in atan2 at - line 5.
096c060c 967Use of uninitialized value $m1 in atan2 at - line 5.
29489e7c
DM
968Use of uninitialized value $m1 in sin at - line 6.
969Use of uninitialized value $m1 in cos at - line 7.
970Use of uninitialized value $m1 in rand at - line 8.
971Use of uninitialized value $m1 in srand at - line 9.
972Use of uninitialized value $m1 in exp at - line 10.
973Use of uninitialized value $m1 in log at - line 11.
974Use of uninitialized value $m1 in sqrt at - line 12.
975Use of uninitialized value $m1 in hex at - line 13.
976Use of uninitialized value $m1 in oct at - line 14.
9f621bb0 977Use of uninitialized value $_ in oct at - line 15.
29489e7c
DM
978########
979use warnings 'uninitialized';
980my ($m1, $v);
981our ($g1);
982
983$v = substr $m1, $g1;
984$v = substr $m1, $g1, $m2;
985$v = substr $m1, $g1, $m2, $g2; undef $m1;
986substr($m1, $g1) = $g2; undef $m1; # NB global2
987substr($m1, $g1, $m2) = $g2; undef $m1; # isn't identified
988
989$v = eval {vec ($m1, $g1, $m2)};
990eval {vec ($m1, $g1, $m2) = $g2}; undef $m1; # ditto
991
992$v = index $m1, $m2;
993$v = index $m1, $m2, $g1;
994$v = rindex $m1, $m2;
995$v = rindex $m1, $m2, $g1;
996EXPECT
997Use of uninitialized value $g1 in substr at - line 5.
998Use of uninitialized value $m1 in substr at - line 5.
999Use of uninitialized value $m2 in substr at - line 6.
1000Use of uninitialized value $g1 in substr at - line 6.
1001Use of uninitialized value $m1 in substr at - line 6.
29489e7c
DM
1002Use of uninitialized value $m2 in substr at - line 7.
1003Use of uninitialized value $g1 in substr at - line 7.
24fcb59f 1004Use of uninitialized value $g2 in substr at - line 7.
29489e7c 1005Use of uninitialized value $m1 in substr at - line 7.
29489e7c 1006Use of uninitialized value $g1 in substr at - line 8.
24fcb59f
FC
1007Use of uninitialized value $g2 in substr at - line 8.
1008Use of uninitialized value $m1 in substr at - line 8.
29489e7c
DM
1009Use of uninitialized value $m2 in substr at - line 9.
1010Use of uninitialized value $g1 in substr at - line 9.
24fcb59f
FC
1011Use of uninitialized value $g2 in substr at - line 9.
1012Use of uninitialized value $m1 in substr at - line 9.
29489e7c
DM
1013Use of uninitialized value $m2 in vec at - line 11.
1014Use of uninitialized value $g1 in vec at - line 11.
1015Use of uninitialized value $m1 in vec at - line 11.
1016Use of uninitialized value $m2 in vec at - line 12.
1017Use of uninitialized value $g1 in vec at - line 12.
29489e7c
DM
1018Use of uninitialized value $m1 in index at - line 14.
1019Use of uninitialized value $m2 in index at - line 14.
1020Use of uninitialized value $g1 in index at - line 15.
1021Use of uninitialized value $m1 in index at - line 15.
1022Use of uninitialized value $m2 in index at - line 15.
29489e7c 1023Use of uninitialized value $m1 in rindex at - line 16.
73ee8be2 1024Use of uninitialized value $m2 in rindex at - line 16.
29489e7c 1025Use of uninitialized value $g1 in rindex at - line 17.
29489e7c 1026Use of uninitialized value $m1 in rindex at - line 17.
73ee8be2 1027Use of uninitialized value $m2 in rindex at - line 17.
29489e7c
DM
1028########
1029use warnings 'uninitialized';
1030my ($m1, $v);
1031our ($g1);
1032
1033$v = sprintf $m1;
1034$v = sprintf '%d%d%d%d', $m1, $m2, $g1, $g2;
094236a2 1035my $m3; eval {formline $m3 };
29489e7c
DM
1036formline '@<<@<<@<<@<<', $m1, $m2, $g1, $g2;
1037EXPECT
1038Use of uninitialized value $m1 in sprintf at - line 5.
1039Use of uninitialized value $m1 in sprintf at - line 6.
1040Use of uninitialized value $m2 in sprintf at - line 6.
1041Use of uninitialized value $g1 in sprintf at - line 6.
1042Use of uninitialized value $g2 in sprintf at - line 6.
094236a2 1043Use of uninitialized value $m3 in formline at - line 7.
29489e7c
DM
1044Use of uninitialized value $m1 in formline at - line 8.
1045Use of uninitialized value $m2 in formline at - line 8.
1046Use of uninitialized value $g1 in formline at - line 8.
1047Use of uninitialized value $g2 in formline at - line 8.
1048########
ce197e4f 1049# SKIP ? !$Config{d_crypt}
29489e7c
DM
1050use warnings 'uninitialized';
1051my ($m1, $v);
1052our ($g1);
1053
1054$v = crypt $m1, $g1;
1055
1056$v = ord;
1057$v = ord $m1;
1058$v = chr;
1059$v = chr $m1;
1060
29489e7c
DM
1061$v = ucfirst;
1062$v = ucfirst $m1;
1063$v = lcfirst;
1064$v = lcfirst $m1;
1065$v = uc;
1066$v = uc $m1;
1067$v = lc;
1068$v = lc $m1;
1069
1070$v = quotemeta;
1071$v = quotemeta $m1;
1072EXPECT
1073Use of uninitialized value $m1 in crypt at - line 5.
1074Use of uninitialized value $g1 in crypt at - line 5.
1075Use of uninitialized value $_ in ord at - line 7.
1076Use of uninitialized value $m1 in ord at - line 8.
1077Use of uninitialized value $_ in chr at - line 9.
1078Use of uninitialized value $m1 in chr at - line 10.
0a0ffbce
RGS
1079Use of uninitialized value $_ in ucfirst at - line 12.
1080Use of uninitialized value $m1 in ucfirst at - line 13.
1081Use of uninitialized value $_ in lcfirst at - line 14.
1082Use of uninitialized value $m1 in lcfirst at - line 15.
1083Use of uninitialized value $_ in uc at - line 16.
1084Use of uninitialized value $m1 in uc at - line 17.
1085Use of uninitialized value $_ in lc at - line 18.
1086Use of uninitialized value $m1 in lc at - line 19.
1087Use of uninitialized value $_ in quotemeta at - line 21.
1088Use of uninitialized value $m1 in quotemeta at - line 22.
29489e7c
DM
1089########
1090use warnings 'uninitialized';
1091my ($m1, $v1, $v2, $v3, $v4);
1092our ($g1);
1093
1094($v1,$v2,$v3,$v4) = split;
1095($v1,$v2,$v3,$v4) = split $m1;
1096($v1,$v2,$v3,$v4) = split $m1, $m2;
1097($v1,$v2,$v3,$v4) = split $m1, $m2, $g1;
1098
1099$v1 = join $m1;
1100$v2 = join $m1, $m2;
1101$v3 = join $m1, $m2, $m3;
1102EXPECT
1103Use of uninitialized value $_ in split at - line 5.
1104Use of uninitialized value $m1 in regexp compilation at - line 6.
1105Use of uninitialized value $_ in split at - line 6.
1106Use of uninitialized value $m1 in regexp compilation at - line 7.
1107Use of uninitialized value $m2 in split at - line 7.
1108Use of uninitialized value $m1 in regexp compilation at - line 8.
1109Use of uninitialized value $g1 in split at - line 8.
1110Use of uninitialized value $m2 in split at - line 8.
1111Use of uninitialized value $m1 in join or string at - line 10.
29489e7c
DM
1112Use of uninitialized value $m2 in join or string at - line 11.
1113Use of uninitialized value $m1 in join or string at - line 12.
1114Use of uninitialized value $m2 in join or string at - line 12.
1115Use of uninitialized value $m3 in join or string at - line 12.
1116########
1117use warnings 'uninitialized';
1118my ($m1, $m2, @ma, $v);
1119
1120our @foo1=(1,undef); chomp @foo1;
1121my @foo2=(1,undef); chomp @foo2;
1122our @foo3=(1,undef); chop @foo3;
1123my @foo4=(1,undef); chop @foo4;
1124our @foo5=(1,undef); $v = sprintf "%s%s",@foo5;
1125my @foo6=(1,undef); $v = sprintf "%s%s",@foo6;
26848657
YO
1126our %foo7=('foo'=>'bar','baz'=>undef); $v = sprintf "%s%s%s%s",%foo7;
1127my %foo8=('foo'=>'bar','baz'=>undef); $v = sprintf "%s%s%s%s",%foo8;
29489e7c
DM
1128our @foo9 =(1,undef); $v = sprintf "%s%s%s%s",$m1,@foo9, $ma[2];
1129my @foo10=(1,undef); $v = sprintf "%s%s%s%s",$m2,@foo10,$ma[2];
1130our %foo11=('foo'=>'bar','baz'=>undef); $v = join '', %foo11;
1131my %foo12=('foo'=>'bar','baz'=>undef); $v = join '', %foo12;
1132our %foo13=(1..2000,'foo'=>'bar','baz'=>undef); $v = join '', %foo13;
1133my %foo14=(1..2000,'foo'=>'bar','baz'=>undef); $v = join '', %foo14;
1134EXPECT
1135Use of uninitialized value $foo1[1] in chomp at - line 4.
1136Use of uninitialized value $foo2[1] in chomp at - line 5.
1137Use of uninitialized value $foo3[1] in chop at - line 6.
1138Use of uninitialized value $foo4[1] in chop at - line 7.
1139Use of uninitialized value $foo5[1] in sprintf at - line 8.
1140Use of uninitialized value $foo6[1] in sprintf at - line 9.
1141Use of uninitialized value $foo7{"baz"} in sprintf at - line 10.
1142Use of uninitialized value $foo8{"baz"} in sprintf at - line 11.
1143Use of uninitialized value $m1 in sprintf at - line 12.
1144Use of uninitialized value $foo9[1] in sprintf at - line 12.
1145Use of uninitialized value in sprintf at - line 12.
1146Use of uninitialized value $m2 in sprintf at - line 13.
1147Use of uninitialized value $foo10[1] in sprintf at - line 13.
1148Use of uninitialized value in sprintf at - line 13.
1149Use of uninitialized value $foo11{"baz"} in join or string at - line 14.
1150Use of uninitialized value $foo12{"baz"} in join or string at - line 15.
1151Use of uninitialized value within %foo13 in join or string at - line 16.
1152Use of uninitialized value within %foo14 in join or string at - line 17.
1153########
1154use warnings 'uninitialized';
1155my ($v);
1156
1157undef $^A; $v = $^A + ${^FOO}; # should output '^A' not chr(1)
1158*GLOB1 = *GLOB2;
1159$v = $GLOB1 + 1;
1160$v = $GLOB2 + 1;
1161EXPECT
1162Use of uninitialized value $^FOO in addition (+) at - line 4.
1163Use of uninitialized value $^A in addition (+) at - line 4.
1164Use of uninitialized value $GLOB1 in addition (+) at - line 6.
1165Use of uninitialized value $GLOB2 in addition (+) at - line 7.
1166########
1167use warnings 'uninitialized';
1168my ($v);
1169
1170# check hash key is sanitised
d7cf15ed 1171my %h = ("\0011\002\r\n\t\f\"\\\x{1234}abcdefghijklmnopqrstuvwxyz", undef);
29489e7c
DM
1172$v = join '', %h;
1173EXPECT
d7cf15ed 1174Use of uninitialized value $h{"\0011\2\r\n\t\f\"\\\x{1234}abcde"...} in join or string at - line 6.
29489e7c
DM
1175########
1176use warnings 'uninitialized';
1177my ($m1, $v);
1178our ($g1);
1179
1180$v = eval { \&$m1 };
1181$v = eval { \&$g1 };
1182
1183my @a;
1184@a = splice @a, $m1, $g1;
1185$v = 1 + splice @a, $m1, $g1;
1186
1187my $x = bless [], 'Z';
1188eval { $x->$m1() };
1189
1190eval { &$m1() };
1191eval { &$g1() };
1192
1193warn $m1,$g1,"foo";
1194
1195eval { die $m1, $g1 };
1196
1197reset $m1;
1198reset $g1;
1199EXPECT
1200Use of uninitialized value $m1 in subroutine dereference at - line 5.
29489e7c
DM
1201Use of uninitialized value $g1 in subroutine dereference at - line 6.
1202Use of uninitialized value $m1 in splice at - line 9.
1203Use of uninitialized value $g1 in splice at - line 9.
1204Use of uninitialized value $m1 in splice at - line 10.
1205Use of uninitialized value $g1 in splice at - line 10.
1206Use of uninitialized value in addition (+) at - line 10.
1207Use of uninitialized value $m1 in method lookup at - line 13.
29489e7c
DM
1208Use of uninitialized value $m1 in warn at - line 18.
1209Use of uninitialized value $g1 in warn at - line 18.
1210foo at - line 18.
1211Use of uninitialized value $m1 in die at - line 20.
1212Use of uninitialized value $g1 in die at - line 20.
1213Use of uninitialized value $m1 in symbol reset at - line 22.
1214Use of uninitialized value $g1 in symbol reset at - line 23.
1215########
1216use warnings 'uninitialized';
1217my ($m1);
1218our ($g1);
1219
1220open FOO; # accesses $FOO
1221my $foo = 'FO';
1222open($foo."O"); # accesses $FOO
1223open my $x; # accesses ${*$x}
1224open $foobar; # accesses ${*$foobar}
1225my $y;
1226open $y, $m1;
1227eval { open $y, $m1, $g1 };
1228open $y, '<', $g1;
1229
1230sysopen $y, $m1, $m2;
1231sysopen $y, $m1, $g1, $m2;
1232
1233my $old = umask;
1234umask $m1;
1235umask $g1;
1236umask $old;
1237
1238binmode STDIN, $m1;
1239EXPECT
1240Use of uninitialized value $FOO in open at - line 5.
1241Use of uninitialized value in open at - line 7.
1242Use of uninitialized value in open at - line 8.
1243Use of uninitialized value in open at - line 9.
1244Use of uninitialized value $m1 in open at - line 11.
1245Use of uninitialized value $m1 in open at - line 12.
1246Use of uninitialized value $g1 in open at - line 13.
1247Use of uninitialized value $m2 in sysopen at - line 15.
1248Use of uninitialized value $m1 in sysopen at - line 15.
1249Use of uninitialized value $m2 in sysopen at - line 16.
1250Use of uninitialized value $g1 in sysopen at - line 16.
1251Use of uninitialized value $m1 in sysopen at - line 16.
1252Use of uninitialized value $m1 in umask at - line 19.
1253Use of uninitialized value $g1 in umask at - line 20.
1254Use of uninitialized value $m1 in binmode at - line 23.
29489e7c
DM
1255########
1256use warnings 'uninitialized';
1257my ($m1);
1258our ($g1);
1259
1260eval { my $x; tie $x, $m1 };
1261
1262eval { my $x; read $m1, $x, $g1 };
1263eval { my $x; read $m1, $x, $g1, $g2 };
1264eval { my $x; sysread $m1, $x, $g1 };
1265eval { my $x; sysread $m1, $x, $g1, $g2 };
1266EXPECT
1267Use of uninitialized value $m1 in tie at - line 5.
29489e7c
DM
1268Use of uninitialized value $m1 in ref-to-glob cast at - line 7.
1269Use of uninitialized value $g1 in read at - line 7.
1270Use of uninitialized value $m1 in ref-to-glob cast at - line 8.
1271Use of uninitialized value $g1 in read at - line 8.
1272Use of uninitialized value $g2 in read at - line 8.
1273Use of uninitialized value $m1 in ref-to-glob cast at - line 9.
1274Use of uninitialized value $g1 in sysread at - line 9.
1275Use of uninitialized value $m1 in ref-to-glob cast at - line 10.
1276Use of uninitialized value $g1 in sysread at - line 10.
1277Use of uninitialized value $g2 in sysread at - line 10.
1278########
1279use warnings 'uninitialized';
1280my ($m1);
1281our ($g1, @ga);
1282
1283printf $m1;
1284printf STDERR "%d%d%d%d\n", $m1, $m2, $g1, $g2;
1285printf $ga[1000];
1286printf STDERR "FOO1:%s\n", $ga[1000];
1287printf STDERR "FOO2:%s%s%s%s\n", $m1, $g1, $ga[1],$m2;
1288printf STDERR "FOO3:%s%s%s\n", "X", $ga[1],"Y";
1289EXPECT
1290Use of uninitialized value $m1 in printf at - line 5.
1291Use of uninitialized value $m1 in printf at - line 6.
1292Use of uninitialized value $m2 in printf at - line 6.
1293Use of uninitialized value $g1 in printf at - line 6.
1294Use of uninitialized value $g2 in printf at - line 6.
12950000
fa8d1836
DM
1296Use of uninitialized value in printf at - line 7.
1297Use of uninitialized value in printf at - line 8.
29489e7c
DM
1298FOO1:
1299Use of uninitialized value $m1 in printf at - line 9.
1300Use of uninitialized value $g1 in printf at - line 9.
1301Use of uninitialized value in printf at - line 9.
1302Use of uninitialized value $m2 in printf at - line 9.
1303FOO2:
fa8d1836 1304Use of uninitialized value in printf at - line 10.
29489e7c
DM
1305FOO3:XY
1306########
1307use warnings 'uninitialized';
1308my ($m1);
1309our ($g1);
1310
1311eval { my $x; seek $x,$m1, $g1 };
1312eval { my $x; sysseek $x,$m1, $g1 };
c9cb0f41 1313eval { syswrite $m1, $g1 }; # logic changed - now won't try $g1 if $m1 is bad
96d52181
DM
1314# eval { syswrite STDERR, $m1 }; # XXX under utf8, can give
1315# eval { syswrite STDERR, $m1, $g1 }; # XXX different warnings
1316# eval { syswrite STDERR, $m1, $g1, $m2 };
29489e7c
DM
1317eval { my $x; socket $x, $m1, $g1, $m2 };
1318eval { my ($x,$y); socketpair $x, $y, $m1, $g1, $m2 };
1319EXPECT
1320Use of uninitialized value $x in ref-to-glob cast at - line 5.
1321Use of uninitialized value $g1 in seek at - line 5.
1322Use of uninitialized value $m1 in seek at - line 5.
1323Use of uninitialized value $x in ref-to-glob cast at - line 6.
1324Use of uninitialized value $g1 in sysseek at - line 6.
1325Use of uninitialized value $m1 in sysseek at - line 6.
1326Use of uninitialized value $m1 in ref-to-glob cast at - line 7.
c162e49a
CB
1327Use of uninitialized value $m2 in socket at - line 11.
1328Use of uninitialized value $g1 in socket at - line 11.
1329Use of uninitialized value $m1 in socket at - line 11.
1330Use of uninitialized value $m2 in socketpair at - line 12.
1331Use of uninitialized value $g1 in socketpair at - line 12.
1332Use of uninitialized value $m1 in socketpair at - line 12.
1333########
1334use Config;
1335BEGIN {
1336 if ( !$Config{d_flock} &&
1337 !$Config{d_fcntl_can_lock} &&
1338 !$Config{d_lockf} ) {
1339 print <<EOM ;
1340SKIPPED
1341# flock not present
1342EOM
1343 exit ;
1344 }
1345}
1346use warnings 'uninitialized';
1347our ($g1);
1348
1349eval { my $x; flock $x, $g1 };
1350EXPECT
1351Use of uninitialized value $x in ref-to-glob cast at - line 16.
1352Use of uninitialized value $g1 in flock at - line 16.
29489e7c
DM
1353########
1354use warnings 'uninitialized';
1355my ($m1, $v);
1356our ($g1);
1357
1358stat;
1359lstat;
1360stat $m1;
1361lstat $g1;
1362
1363$v = -R $m1;
1364$v = -W $m1;
1365$v = -X $m1;
1366$v = -r $m1;
1367$v = -w $m1;
1368$v = -x $m1;
1369$v = -e $m1;
29489e7c 1370$v = -o $m1;
945fa9b5 1371$v = -O $m1;
29489e7c
DM
1372$v = -z $m1;
1373$v = -s $m1;
1374$v = -M $m1;
1375$v = -A $m1;
1376$v = -C $m1;
1377$v = -S $m1;
1378$v = -c $m1;
1379$v = -b $m1;
1380$v = -f $m1;
1381$v = -d $m1;
1382$v = -p $m1;
1383$v = -l $m1;
1384$v = -u $m1;
1385$v = -g $m1;
96d52181 1386# $v = -k $m1; # XXX this is a no-op under win32
29489e7c
DM
1387$v = -t $m1;
1388$v = -T $m1;
1389$v = -B $m1;
1390EXPECT
1391Use of uninitialized value $_ in stat at - line 5.
1392Use of uninitialized value $_ in lstat at - line 6.
1393Use of uninitialized value $m1 in stat at - line 7.
1394Use of uninitialized value $g1 in lstat at - line 8.
1395Use of uninitialized value $m1 in -R at - line 10.
1396Use of uninitialized value $m1 in -W at - line 11.
1397Use of uninitialized value $m1 in -X at - line 12.
1398Use of uninitialized value $m1 in -r at - line 13.
1399Use of uninitialized value $m1 in -w at - line 14.
1400Use of uninitialized value $m1 in -x at - line 15.
1401Use of uninitialized value $m1 in -e at - line 16.
1402Use of uninitialized value $m1 in -o at - line 17.
1403Use of uninitialized value $m1 in -O at - line 18.
1404Use of uninitialized value $m1 in -z at - line 19.
1405Use of uninitialized value $m1 in -s at - line 20.
1406Use of uninitialized value $m1 in -M at - line 21.
1407Use of uninitialized value $m1 in -A at - line 22.
1408Use of uninitialized value $m1 in -C at - line 23.
1409Use of uninitialized value $m1 in -S at - line 24.
1410Use of uninitialized value $m1 in -c at - line 25.
1411Use of uninitialized value $m1 in -b at - line 26.
1412Use of uninitialized value $m1 in -f at - line 27.
1413Use of uninitialized value $m1 in -d at - line 28.
1414Use of uninitialized value $m1 in -p at - line 29.
1415Use of uninitialized value $m1 in -l at - line 30.
29489e7c
DM
1416Use of uninitialized value $m1 in -u at - line 31.
1417Use of uninitialized value $m1 in -g at - line 32.
29489e7c
DM
1418Use of uninitialized value $m1 in -t at - line 34.
1419Use of uninitialized value $m1 in -T at - line 35.
1420Use of uninitialized value $m1 in -B at - line 36.
1421########
1422use warnings 'uninitialized';
1423my ($m1, $v);
1424our ($g1);
1425
1426$v = localtime $m1;
1427$v = gmtime $g1;
1428EXPECT
1429Use of uninitialized value $m1 in localtime at - line 5.
1430Use of uninitialized value $g1 in gmtime at - line 6.
1431########
1432use warnings 'uninitialized';
50edf520 1433my ($m1, $m2, $v);
29489e7c
DM
1434
1435$v = eval;
1436$v = eval $m1;
50edf520 1437$m2 = q($m1); $v = 1 + eval $m2;
29489e7c
DM
1438EXPECT
1439Use of uninitialized value $_ in eval "string" at - line 4.
29489e7c 1440Use of uninitialized value $m1 in eval "string" at - line 5.
50edf520 1441Use of uninitialized value in addition (+) at - line 6.
29489e7c
DM
1442########
1443use warnings 'uninitialized';
1444my ($m1);
1445
1446exit $m1;
1447EXPECT
1448Use of uninitialized value $m1 in exit at - line 4.
12e06b6f 1449########
12e06b6f
NC
1450use warnings 'uninitialized';
1451my $undef;
1452
1453if ($undef == 3) {
1454} elsif ($undef == 0) {
1455}
1456EXPECT
1457Use of uninitialized value $undef in numeric eq (==) at - line 4.
1458Use of uninitialized value $undef in numeric eq (==) at - line 5.
1459########
79851868
NC
1460# TODO long standing bug - conditions of while loops
1461use warnings;
1462
1463my $c;
1464my $d = 1;
1465while ($c == 0 && $d) {
1466 # a
1467 # few
1468 # blank
1469 # lines
1470 undef $d;
1471}
1472EXPECT
1473Use of uninitialized value $c in numeric eq (==) at - line 5.
1474Use of uninitialized value $c in numeric eq (==) at - line 5.
1475########
d12f7a6a
NC
1476# TODO long standing bug - conditions of until loops
1477use warnings;
1478
1479my $c;
1480my $d;
1481until ($c == 1) {
1482 # a
1483 # few
1484 # blank
1485 # lines
1486 $c = 1 if ++$d == 2;
1487}
1488EXPECT
1489Use of uninitialized value $c in numeric eq (==) at - line 5.
1490Use of uninitialized value $c in numeric eq (==) at - line 5.
1491########
1492# TODO long standing bug - conditions of for loops
1493use warnings;
1494
1495my $c;
1496my $d;
1497for ($d = 1; $c == 0 && $d; ) {
1498 # a
1499 # few
1500 # blank
1501 # lines
1502 undef $d;
1503}
1504
1505my $e;
1506for ($d = 2; $d > 0; $e = !($c == 0)) {
1507 # a
1508 # few
1509 # blank
1510 # lines
1511 --$d;
1512}
1513EXPECT
1514Use of uninitialized value $c in numeric eq (==) at - line 5.
1515Use of uninitialized value $c in numeric eq (==) at - line 5.
1516Use of uninitialized value $c in numeric eq (==) at - line 14.
1517Use of uninitialized value $c in numeric eq (==) at - line 14.
1518########
12e06b6f
NC
1519# TODO long standing bug - more general variant of the above problem
1520use warnings;
1521my $undef;
1522
1523my $a = $undef + 1;
1524my $b
1525 = $undef
1526 + 1;
1527EXPECT
1528Use of uninitialized value $undef in addition (+) at - line 4.
1529Use of uninitialized value $undef in addition (+) at - line 7.
1e21d011
B
1530########
1531use warnings 'uninitialized';
1532my ($r1, $r2);
1533$_ = undef;
1534$v = reverse;
1535$v = reverse $r1;
1536$v = reverse "abc", $r2, "def";
1537EXPECT
1538Use of uninitialized value in reverse at - line 4.
1539Use of uninitialized value $r1 in reverse at - line 5.
1540Use of uninitialized value $r2 in reverse at - line 6.
8b0dea50
DM
1541########
1542use warnings 'uninitialized';
1543#
1544# ops that can return undef for defined args
0b9c91f6 1545# split into separate tests to diagnose the cause of daily build smoke
8b0dea50 1546#
928cb7d4 1547# *** `` not tested: Windows produces an error on STDERR
a3ed38f2 1548# *** ditto qx()
8b0dea50 1549# *** pipe() not tested
8b0dea50
DM
1550# *** ioctl not tested
1551# *** socket not tested
1552# *** socketpair not tested
1553# *** bind not tested
1554# *** connect not tested
1555# *** listen not tested
8b0dea50
DM
1556# *** shutdown not tested
1557# *** setsockopt not tested
1558# *** getpeername not tested
0b9c91f6
NC
1559# *** readdir not tested
1560# *** telldir not tested
1561# *** seekdir not tested
1562# *** rewinddir not tested
1563# *** closedir not tested
1564# *** gmtime not tested
1565# *** alarm not tested
1566# *** semget not tested
1567# *** getlogin not tested
1568EXPECT
1569########
1570use warnings 'uninitialized';
2234743e
NC
1571if ($^O eq 'MSWin32') {
1572 print <<'EOM';
1573SKIPPED
1574# `` produces an error on STDERR on Win32
1575EOM
1576 exit;
1577}
1578my $nocmd = '/no/such/command';
1579my $v;
1580$v = 1 + `$nocmd`;
1581EXPECT
1582Use of uninitialized value in addition (+) at - line 11.
1583########
1584use warnings 'uninitialized';
1585if ($^O eq 'MSWin32') {
1586 print <<'EOM';
1587SKIPPED
1588# qx produces an error on STDERR on Win32
1589EOM
1590 exit;
1591}
1592my $nocmd = '/no/such/command';
1593my $v;
1594$v = 1 + qx($nocmd);
1595EXPECT
1596Use of uninitialized value in addition (+) at - line 11.
1597########
1598use warnings 'uninitialized';
1599my $nan = "NaN";
1600if ($nan == $nan) {
1601 print <<'EOM';
1602SKIPPED
1603# NaN not supported here.
1604EOM
1605 exit;
1606}
1607my $v;
1608$v = 1 + ($nan <=> 1);
1609EXPECT
1610Use of uninitialized value in addition (+) at - line 11.
1611########
1612use warnings 'uninitialized';
1613if ($^O eq 'MSWin32') {
1614 print <<'EOM';
1615SKIPPED
1616# -k produces no warning on Win32
1617EOM
1618 exit;
1619}
1620my $nofile = '/no/such/file';
1621my $v;
1622$v = 1 + -k $nofile;
1623EXPECT
1624Use of uninitialized value in addition (+) at - line 11.
1625########
1626use warnings 'uninitialized';
0b9c91f6
NC
1627my $nofile = '/no/such/file';
1628my $v;
1629my $f = "";
1630$v = 1 + open($f, $nofile);
1631EXPECT
1632Use of uninitialized value in addition (+) at - line 5.
1633########
1634use warnings 'uninitialized';
1635my $nofile = '/no/such/file';
1636my $v;
1637$v = 1 + fileno($nofile);
1638EXPECT
1639Use of uninitialized value in addition (+) at - line 4.
1640########
1641use warnings 'uninitialized';
1642my $nofile = '/no/such/file';
1643my $v;
1644$v = 1 + binmode($nofile);
1645EXPECT
1646Use of uninitialized value in addition (+) at - line 4.
1647########
1648use warnings 'uninitialized';
1649my $nofile = '/no/such/file';
1650my $v;
1651$v = 1 + tied($nofile);
1652EXPECT
1653Use of uninitialized value in addition (+) at - line 4.
1654########
1655use warnings 'uninitialized';
1656my $nofile = '/no/such/file';
1657my $v;
1658$v = 1 + getc($nofile);
1659EXPECT
1660Use of uninitialized value in addition (+) at - line 4.
1661########
1662use warnings 'uninitialized';
1663my $nofile = '/no/such/file';
1664my $v;
1665$v = 1 + sysread($nofile, my $buf,1);
1666EXPECT
1667Use of uninitialized value in addition (+) at - line 4.
1668########
1669use warnings 'uninitialized';
1670my $nofile = '/no/such/file';
1671my $v;
1672$v = 1 + eval { send($nofile, $buf,0) };
1673EXPECT
1674Use of uninitialized value in addition (+) at - line 4.
1675########
1676use warnings 'uninitialized';
1677my $nofile = '/no/such/file';
1678my $v;
1679my $fh = "";
1680$v = 1 + eval { accept($fh, $nofile) };
1681EXPECT
1682Use of uninitialized value in addition (+) at - line 5.
1683########
1684use warnings 'uninitialized';
1685my $nofile = '/no/such/file';
1686my $v;
8b0dea50 1687$v = 1 + (-r $nofile);
0b9c91f6
NC
1688EXPECT
1689Use of uninitialized value in addition (+) at - line 4.
1690########
1691use warnings 'uninitialized';
1692my $nofile = '/no/such/file';
1693my $v;
8b0dea50 1694$v = 1 + (-w $nofile);
0b9c91f6
NC
1695EXPECT
1696Use of uninitialized value in addition (+) at - line 4.
1697########
1698use warnings 'uninitialized';
1699my $nofile = '/no/such/file';
1700my $v;
8b0dea50 1701$v = 1 + (-x $nofile);
0b9c91f6
NC
1702EXPECT
1703Use of uninitialized value in addition (+) at - line 4.
1704########
1705use warnings 'uninitialized';
1706my $nofile = '/no/such/file';
1707my $v;
8b0dea50 1708$v = 1 + (-o $nofile);
0b9c91f6
NC
1709EXPECT
1710Use of uninitialized value in addition (+) at - line 4.
1711########
1712use warnings 'uninitialized';
1713my $nofile = '/no/such/file';
1714my $v;
8b0dea50 1715$v = 1 + (-R $nofile);
0b9c91f6
NC
1716EXPECT
1717Use of uninitialized value in addition (+) at - line 4.
1718########
1719use warnings 'uninitialized';
1720my $nofile = '/no/such/file';
1721my $v;
8b0dea50 1722$v = 1 + (-W $nofile);
0b9c91f6
NC
1723EXPECT
1724Use of uninitialized value in addition (+) at - line 4.
1725########
1726use warnings 'uninitialized';
1727my $nofile = '/no/such/file';
1728my $v;
8b0dea50 1729$v = 1 + (-X $nofile);
0b9c91f6
NC
1730EXPECT
1731Use of uninitialized value in addition (+) at - line 4.
1732########
1733use warnings 'uninitialized';
1734my $nofile = '/no/such/file';
1735my $v;
8b0dea50 1736$v = 1 + (-O $nofile);
0b9c91f6
NC
1737EXPECT
1738Use of uninitialized value in addition (+) at - line 4.
1739########
1740use warnings 'uninitialized';
1741my $nofile = '/no/such/file';
1742my $v;
8b0dea50 1743$v = 1 + (-e $nofile);
0b9c91f6
NC
1744EXPECT
1745Use of uninitialized value in addition (+) at - line 4.
1746########
1747use warnings 'uninitialized';
1748my $nofile = '/no/such/file';
1749my $v;
8b0dea50 1750$v = 1 + (-z $nofile);
0b9c91f6
NC
1751EXPECT
1752Use of uninitialized value in addition (+) at - line 4.
1753########
1754use warnings 'uninitialized';
1755my $nofile = '/no/such/file';
1756my $v;
8b0dea50 1757$v = 1 + (-s $nofile);
0b9c91f6
NC
1758EXPECT
1759Use of uninitialized value in addition (+) at - line 4.
1760########
1761use warnings 'uninitialized';
1762my $nofile = '/no/such/file';
1763my $v;
8b0dea50 1764$v = 1 + (-f $nofile);
0b9c91f6
NC
1765EXPECT
1766Use of uninitialized value in addition (+) at - line 4.
1767########
1768use warnings 'uninitialized';
1769my $nofile = '/no/such/file';
1770my $v;
8b0dea50 1771$v = 1 + (-d $nofile);
0b9c91f6
NC
1772EXPECT
1773Use of uninitialized value in addition (+) at - line 4.
1774########
1775use warnings 'uninitialized';
1776my $nofile = '/no/such/file';
1777my $v;
8b0dea50 1778$v = 1 + (-l $nofile);
0b9c91f6
NC
1779EXPECT
1780Use of uninitialized value in addition (+) at - line 4.
1781########
1782use warnings 'uninitialized';
1783my $nofile = '/no/such/file';
1784my $v;
8b0dea50 1785$v = 1 + (-p $nofile);
0b9c91f6
NC
1786EXPECT
1787Use of uninitialized value in addition (+) at - line 4.
1788########
1789use warnings 'uninitialized';
1790my $nofile = '/no/such/file';
1791my $v;
8b0dea50 1792$v = 1 + (-S $nofile);
0b9c91f6
NC
1793EXPECT
1794Use of uninitialized value in addition (+) at - line 4.
1795########
1796use warnings 'uninitialized';
1797my $nofile = '/no/such/file';
1798my $v;
8b0dea50 1799$v = 1 + (-b $nofile);
0b9c91f6
NC
1800EXPECT
1801Use of uninitialized value in addition (+) at - line 4.
1802########
1803use warnings 'uninitialized';
1804my $nofile = '/no/such/file';
1805my $v;
8b0dea50 1806$v = 1 + (-c $nofile);
0b9c91f6
NC
1807EXPECT
1808Use of uninitialized value in addition (+) at - line 4.
1809########
1810use warnings 'uninitialized';
1811my $nofile = '/no/such/file';
1812my $v;
8b0dea50 1813$v = 1 + (-t $nofile);
0b9c91f6
NC
1814EXPECT
1815Use of uninitialized value in addition (+) at - line 4.
1816########
1817use warnings 'uninitialized';
1818my $nofile = '/no/such/file';
1819my $v;
8b0dea50 1820$v = 1 + (-u $nofile);
0b9c91f6
NC
1821EXPECT
1822Use of uninitialized value in addition (+) at - line 4.
1823########
1824use warnings 'uninitialized';
1825my $nofile = '/no/such/file';
1826my $v;
8b0dea50 1827$v = 1 + (-g $nofile);
0b9c91f6
NC
1828EXPECT
1829Use of uninitialized value in addition (+) at - line 4.
1830########
1831use warnings 'uninitialized';
1832my $nofile = '/no/such/file';
1833my $v;
8b0dea50 1834$v = 1 + (-T $nofile);
0b9c91f6
NC
1835EXPECT
1836Use of uninitialized value in addition (+) at - line 4.
1837########
1838use warnings 'uninitialized';
1839my $nofile = '/no/such/file';
1840my $v;
8b0dea50 1841$v = 1 + (-B $nofile);
0b9c91f6
NC
1842EXPECT
1843Use of uninitialized value in addition (+) at - line 4.
1844########
1845use warnings 'uninitialized';
1846my $nofile = '/no/such/file';
1847my $v;
8b0dea50 1848$v = 1 + (-M $nofile);
0b9c91f6
NC
1849EXPECT
1850Use of uninitialized value in addition (+) at - line 4.
1851########
1852use warnings 'uninitialized';
1853my $nofile = '/no/such/file';
1854my $v;
8b0dea50 1855$v = 1 + (-A $nofile);
0b9c91f6
NC
1856EXPECT
1857Use of uninitialized value in addition (+) at - line 4.
1858########
1859use warnings 'uninitialized';
1860my $nofile = '/no/such/file';
1861my $v;
8b0dea50 1862$v = 1 + (-C $nofile);
0b9c91f6
NC
1863EXPECT
1864Use of uninitialized value in addition (+) at - line 4.
1865########
1866use warnings 'uninitialized';
1867my $nofile = '/no/such/file';
1868my $v;
8b0dea50 1869$v = 1 + eval { readlink $nofile };
0b9c91f6
NC
1870EXPECT
1871Use of uninitialized value in addition (+) at - line 4.
1872########
1873use warnings 'uninitialized';
1874my $nofile = '/no/such/file';
1875my $v;
8b0dea50 1876$v = 1 + opendir($f, $nofile);
0b9c91f6
NC
1877EXPECT
1878Use of uninitialized value in addition (+) at - line 4.
1879########
1880use warnings 'uninitialized';
1881my $nofile = '/no/such/file';
1882my $v;
8b0dea50 1883$v = 1 + undef;
0b9c91f6
NC
1884EXPECT
1885Use of uninitialized value in addition (+) at - line 4.
1886########
1887use warnings 'uninitialized';
1888my $nofile = '/no/such/file';
1889my $v;
8b0dea50 1890my $x = 1; $v = 1 + undef($x);
0b9c91f6
NC
1891EXPECT
1892Use of uninitialized value in addition (+) at - line 4.
1893########
1894use warnings 'uninitialized';
1895my $v;
8b0dea50
DM
1896my $emptys = "";
1897$v = 1 + substr($emptys,2,1);
0b9c91f6
NC
1898EXPECT
1899Use of uninitialized value in addition (+) at - line 4.
1900########
1901use warnings 'uninitialized';
1902my $v;
8b0dea50
DM
1903my @emptya;
1904$v = 1 + each @emptya;
0b9c91f6
NC
1905EXPECT
1906Use of uninitialized value in addition (+) at - line 4.
1907########
1908use warnings 'uninitialized';
1909my $v;
1910my %emptyh;
8b0dea50 1911$v = 1 + each %emptyh;
0b9c91f6
NC
1912EXPECT
1913Use of uninitialized value in addition (+) at - line 4.
1914########
1915use warnings 'uninitialized';
1916my $v;
1917my @emptya;
8b0dea50 1918$v = 1 + sort @emptya;
0b9c91f6
NC
1919EXPECT
1920Use of uninitialized value in addition (+) at - line 4.
1921########
1922use warnings 'uninitialized';
1923my $v;
8b0dea50 1924my $zero = 0; $v = 1 + caller($zero);
0b9c91f6
NC
1925EXPECT
1926Use of uninitialized value in addition (+) at - line 3.
1927########
1928use warnings 'uninitialized';
1929my $nofile = '/no/such/file';
1930my $v;
8b0dea50 1931$v = 1 + do $nofile;
0b9c91f6
NC
1932EXPECT
1933Use of uninitialized value in addition (+) at - line 4.
1934########
1935use warnings 'uninitialized';
1936my $v;
fa8d1836
DM
1937my $fn = sub {};
1938$v = 1 + prototype $fn;
0b9c91f6
NC
1939EXPECT
1940Use of uninitialized value in addition (+) at - line 4.
1941########
0f539b13 1942use warnings 'uninitialized'; no warnings 'experimental::smartmatch';
0b9c91f6
NC
1943my $v;
1944my $fn = sub {};
6ac83b63 1945$v = 1 + (1 ~~ $fn);
0b9c91f6
NC
1946EXPECT
1947Use of uninitialized value in addition (+) at - line 4.
1948########
1949use warnings 'uninitialized';
1950my $v;
1951my $f = "";
fa8d1836 1952$v = 1 + (print STDIN $f); # print to STDIN returns undef
0b9c91f6
NC
1953EXPECT
1954Use of uninitialized value in addition (+) at - line 4.
1955########
1956use warnings 'uninitialized';
1957my $v;
1958my $f = "";
fa8d1836 1959$v = 1 + (printf STDIN "%s", $f);
0b9c91f6
NC
1960EXPECT
1961Use of uninitialized value in addition (+) at - line 4.
1962########
1963use warnings 'uninitialized';
1964my $v;
1965my $f = "";
fa8d1836 1966{ use feature 'say'; $v = 1 + (say STDIN "%s", $f); }
0b9c91f6
NC
1967EXPECT
1968Use of uninitialized value in addition (+) at - line 4.
1969########
1970use warnings 'uninitialized';
1971my $v;
1972my $f = "";
fa8d1836 1973$v = 1 + (unpack("",$f));
0b9c91f6
NC
1974EXPECT
1975Use of uninitialized value in addition (+) at - line 4.
1976########
1977use warnings 'uninitialized';
1978my $nofile = '/no/such/file';
1979my $v;
1980my $f = "";
fa8d1836 1981$v = 1 + sysopen($f, $nofile, 0);
0b9c91f6
NC
1982EXPECT
1983Use of uninitialized value in addition (+) at - line 5.
1984########
1985use warnings 'uninitialized';
1986my $v;
4d6e9c13
GA
1987{ my $x = -1; $v = 1 + sysseek(DATA, $x, 0); }
1988__END__
8b0dea50 1989EXPECT
0b9c91f6 1990Use of uninitialized value in addition (+) at - line 3.
249534c3
FR
1991########
1992use warnings 'uninitialized';
1993delete $::{'Foo::'};
1994my $moo = $Foo::BAR + 42;
1995__END__
1996EXPECT
1997Use of uninitialized value in addition (+) at - line 3.
8f84cc86
FC
1998########
1999use warnings 'uninitialized';
2000use constant {u=>undef, v=>undef};
2001sub foo () {u}
2002sub foo () {v}
2003EXPECT
50de2b3a
FC
2004########
2005# [perl #72090]
2006use warnings 'uninitialized';
2007$a = @$a > 0;
2008EXPECT
2009Use of uninitialized value $a in array dereference at - line 3.
2010Use of uninitialized value in numeric gt (>) at - line 3.
73b42cee
FC
2011########
2012# [perl #103766]
2013use warnings 'uninitialized';
2014"@{[ $x ]}";
2015EXPECT
2016Use of uninitialized value in join or string at - line 3.
3207fc6b
FC
2017########
2018# inside formats
2019use warnings 'uninitialized';
2020my $x;
2021format =
2022@
2023"$x";
2024.
2025write;
2026EXPECT
2027Use of uninitialized value $x in string at - line 6.
40baebf6 2028########
40baebf6
YO
2029# NAME off-by-one error in hash bucket walk in key detection logic
2030use warnings 'uninitialized';
3207fc6b 2031
40baebf6
YO
2032for ( 0 .. 20 ) { # we assume that this means we test keys for every bucket
2033 my %h= ( $_ => undef );
2034 my $s= sprintf "%s", $h{$_};
2035}
2036EXPECT
2037Use of uninitialized value $h{"0"} in sprintf at - line 5.
2038Use of uninitialized value $h{"1"} in sprintf at - line 5.
2039Use of uninitialized value $h{"2"} in sprintf at - line 5.
2040Use of uninitialized value $h{"3"} in sprintf at - line 5.
2041Use of uninitialized value $h{"4"} in sprintf at - line 5.
2042Use of uninitialized value $h{"5"} in sprintf at - line 5.
2043Use of uninitialized value $h{"6"} in sprintf at - line 5.
2044Use of uninitialized value $h{"7"} in sprintf at - line 5.
2045Use of uninitialized value $h{"8"} in sprintf at - line 5.
2046Use of uninitialized value $h{"9"} in sprintf at - line 5.
2047Use of uninitialized value $h{"10"} in sprintf at - line 5.
2048Use of uninitialized value $h{"11"} in sprintf at - line 5.
2049Use of uninitialized value $h{"12"} in sprintf at - line 5.
2050Use of uninitialized value $h{"13"} in sprintf at - line 5.
2051Use of uninitialized value $h{"14"} in sprintf at - line 5.
2052Use of uninitialized value $h{"15"} in sprintf at - line 5.
2053Use of uninitialized value $h{"16"} in sprintf at - line 5.
2054Use of uninitialized value $h{"17"} in sprintf at - line 5.
2055Use of uninitialized value $h{"18"} in sprintf at - line 5.
2056Use of uninitialized value $h{"19"} in sprintf at - line 5.
2057Use of uninitialized value $h{"20"} in sprintf at - line 5.
cd84013a
FC
2058########
2059# NAME SvPOK && SvLEN==0 should not produce uninit warning
2060use warnings 'uninitialized';
2061
2062$v = int(${qr||}); # sv_2iv on a regexp
2063$v = 1.1 * ${qr||}; # sv_2nv on a regexp
2064$v = ${qr||} << 2; # sv_2uv on a regexp
2065
2066sub TIESCALAR{bless[]}
2067sub FETCH {${qr||}}
2068tie $t, "";
2069$v = 1.1 * $t; # sv_2nv on a tied regexp
2070
2071EXPECT
fedf30e1
DM
2072########
2073# multi-level uninitialised array/hash indexes
2074use warnings 'uninitialized';
2075
2076our ($i0, $i2, $i4, $i6, $i8, $i10, $i12);
2077my ($i1, $i3, $i5, $i7, $i9, $i11, $i13);
2078
2079my (@a,%h);
2080my $v;
2081
2082
2083# use enough depth that OP_MULTIDEREF needs more than one action word
2084
2085$v = $a[$i0]{$i1}[$i2]{$i3}[$i4]{$i5}[$i6]{$i7}[$i8]{$i9}[$i10]{$i11}[$i12]{$i13};
2086$v = $h{$i0}[$i1]{$i2}[$i3]{$i4}[$i5]{$i6}[$i7]{$i8}[$i9]{$i10}[$i11]{$i12}[$i13];
2087
2088EXPECT
2089Use of uninitialized value $i0 in array element at - line 13.
2090Use of uninitialized value $i1 in hash element at - line 13.
2091Use of uninitialized value $i2 in array element at - line 13.
2092Use of uninitialized value $i3 in hash element at - line 13.
2093Use of uninitialized value $i4 in array element at - line 13.
2094Use of uninitialized value $i5 in hash element at - line 13.
2095Use of uninitialized value $i6 in array element at - line 13.
2096Use of uninitialized value $i7 in hash element at - line 13.
2097Use of uninitialized value $i8 in array element at - line 13.
2098Use of uninitialized value $i9 in hash element at - line 13.
2099Use of uninitialized value $i10 in array element at - line 13.
2100Use of uninitialized value $i11 in hash element at - line 13.
2101Use of uninitialized value $i12 in array element at - line 13.
2102Use of uninitialized value $i13 in hash element at - line 13.
2103Use of uninitialized value $i0 in hash element at - line 14.
2104Use of uninitialized value $i1 in array element at - line 14.
2105Use of uninitialized value $i2 in hash element at - line 14.
2106Use of uninitialized value $i3 in array element at - line 14.
2107Use of uninitialized value $i4 in hash element at - line 14.
2108Use of uninitialized value $i5 in array element at - line 14.
2109Use of uninitialized value $i6 in hash element at - line 14.
2110Use of uninitialized value $i7 in array element at - line 14.
2111Use of uninitialized value $i8 in hash element at - line 14.
2112Use of uninitialized value $i9 in array element at - line 14.
2113Use of uninitialized value $i10 in hash element at - line 14.
2114Use of uninitialized value $i11 in array element at - line 14.
2115Use of uninitialized value $i12 in hash element at - line 14.
2116Use of uninitialized value $i13 in array element at - line 14.
2117########
2118# misc multideref
2119use warnings 'uninitialized';
2120my ($i,$j,$k);
2121my @a;
2122my @ra = \@a;
2123my $v;
2124$v = exists $a[$i]{$k};
2125$v = delete $a[$i]{$k};
2126$v = local $a[$i]{$k};
2127delete $a[$i]{$k};
2128$v = $ra->[$i+$j]{$k};
2129$v = ($ra//0)->[$i]{$k};
2130$v = $a[length $i]{$k}
2131EXPECT
2132Use of uninitialized value $i in array element at - line 7.
2133Use of uninitialized value $k in exists at - line 7.
2134Use of uninitialized value $i in array element at - line 8.
2135Use of uninitialized value $k in delete at - line 8.
2136Use of uninitialized value $i in array element at - line 9.
2137Use of uninitialized value $k in hash element at - line 9.
2138Use of uninitialized value $k in hash element at - line 9.
2139Use of uninitialized value $k in hash element at - line 9.
2140Use of uninitialized value $i in array element at - line 10.
2141Use of uninitialized value $k in delete at - line 10.
2142Use of uninitialized value $j in addition (+) at - line 11.
2143Use of uninitialized value $i in addition (+) at - line 11.
2144Use of uninitialized value $k in hash element at - line 11.
2145Use of uninitialized value $i in array element at - line 12.
2146Use of uninitialized value $k in hash element at - line 12.
2147Use of uninitialized value $i in array element at - line 13.
2148Use of uninitialized value $k in hash element at - line 13.
51f69a24
AC
2149########
2150# perl #127877
2151use warnings 'uninitialized';
2152my ($p, $q, $r, $s, $t, $u, $v, $w, $x, $y);
2153$p = $p . "a";
2154$q .= "a";
2155$r = $r + 17;
2156$s += 17;
2157$t = $t - 17;
2158$u -= 17;
2159use integer;
2160$v = $v + 17;
2161$w += 17;
2162$x = $x - 17;
2163$y -= 17;
2164EXPECT
2165Use of uninitialized value $p in concatenation (.) or string at - line 4.
2166Use of uninitialized value $r in addition (+) at - line 6.
2167Use of uninitialized value $t in subtraction (-) at - line 8.
2168Use of uninitialized value $v in integer addition (+) at - line 11.
2169Use of uninitialized value $x in integer subtraction (-) at - line 13.
1b3df0e6
FC
2170########
2171# NAME 64-bit array subscripts
2a1ad507 2172# SKIP ? length(pack "p", "") < 8
1b3df0e6
FC
2173use warnings 'uninitialized';
2174
2175# aelem + const
2176use constant foo => \0;
2177$SIG{__WARN__} = sub {
d3ac9355 2178 print STDERR
1b3df0e6
FC
2179 $_[0] =~ /\$a\[([^]]+)]/ && $1 == foo
2180 ? "ok\n"
2181 : ("$1 != ",0+foo,"\n")
2182};
2183() = "$a[foo]";
2184undef $SIG{__WARN__};
2185
2186# Multideref
2187() = "$a[140688675223280]";
2188EXPECT
1b3df0e6 2189ok
d3ac9355 2190Use of uninitialized value $a[140688675223280] in string at - line 15.
6b57d4bc
DM
2191########
2192# RT #128940
2193use warnings 'uninitialized';
2194my $x = "" . open my $fh, "<", "no / such / file";
2195EXPECT
2196Use of uninitialized value in concatenation (.) or string at - line 3.
614f2ce4
DM
2197########
2198# RT #123910
2199# undef's arg being undef doesn't trigger warnings - any warning will be
2200# from tied/magic vars
2201use warnings 'uninitialized';
2202undef $0;
2203EXPECT
2204Use of uninitialized value in undef operator at - line 5.