This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #72090] unitialized variable name wrong with no strict refs
[perl5.git] / t / lib / warnings / sv
CommitLineData
0453d815 1 sv.c
599cee73
PM
2
3 warn(warn_uninit);
4
5 warn(warn_uninit);
6
7 warn(warn_uninit);
8
9 warn(warn_uninit);
10
11 not_a_number(sv);
12
13 not_a_number(sv);
14
15 warn(warn_uninit);
16
17 not_a_number(sv);
18
19 warn(warn_uninit);
20
21 not_a_number(sv);
22
23 not_a_number(sv);
24
25 warn(warn_uninit);
26
27 warn(warn_uninit);
28
29 Subroutine %s redefined
30
31 Invalid conversion in %s:
32
33 Undefined value assigned to typeglob
34
767a6a26
PM
35 Reference is already weak [Perl_sv_rvweaken] <<TODO
36
0453d815
PM
37 Mandatory Warnings
38 ------------------
7e2040f0
GS
39 Malformed UTF-8 character [sv_pos_b2u] (not tested: difficult to produce
40 with perl now)
0453d815
PM
41
42 Mandatory Warnings TODO
43 ------------------
44 Attempt to free non-arena SV: 0x%lx [del_sv]
45 Reference miscount in sv_replace() [sv_replace]
46 Attempt to free unreferenced scalar [sv_free]
47 Attempt to free temp prematurely: SV 0x%lx [sv_free]
48 semi-panic: attempt to dup freed string [newSVsv]
49
599cee73
PM
50
51__END__
52# sv.c
53use integer ;
4438c4b7 54use warnings 'uninitialized' ;
599cee73 55$x = 1 + $a[0] ; # a
4438c4b7 56no warnings 'uninitialized' ;
0453d815 57$x = 1 + $b[0] ; # a
599cee73 58EXPECT
29489e7c 59Use of uninitialized value $a[0] in integer addition (+) at - line 4.
599cee73
PM
60########
61# sv.c (sv_2iv)
62package fred ;
63sub TIESCALAR { my $x ; bless \$x}
64sub FETCH { return undef }
65sub STORE { return 1 }
66package main ;
67tie $A, 'fred' ;
68use integer ;
4438c4b7 69use warnings 'uninitialized' ;
599cee73 70$A *= 2 ;
4438c4b7 71no warnings 'uninitialized' ;
0453d815 72$A *= 2 ;
599cee73 73EXPECT
29489e7c 74Use of uninitialized value $A in integer multiplication (*) at - line 10.
599cee73
PM
75########
76# sv.c
77use integer ;
4438c4b7 78use warnings 'uninitialized' ;
599cee73 79my $x *= 2 ; #b
4438c4b7 80no warnings 'uninitialized' ;
0453d815 81my $y *= 2 ; #b
599cee73 82EXPECT
29489e7c 83Use of uninitialized value $x in integer multiplication (*) at - line 4.
599cee73
PM
84########
85# sv.c (sv_2uv)
86package fred ;
87sub TIESCALAR { my $x ; bless \$x}
88sub FETCH { return undef }
89sub STORE { return 1 }
90package main ;
91tie $A, 'fred' ;
4438c4b7 92use warnings 'uninitialized' ;
599cee73
PM
93$B = 0 ;
94$B |= $A ;
4438c4b7 95no warnings 'uninitialized' ;
0453d815
PM
96$B = 0 ;
97$B |= $A ;
599cee73 98EXPECT
29489e7c 99Use of uninitialized value $A in bitwise or (|) at - line 10.
599cee73
PM
100########
101# sv.c
4438c4b7 102use warnings 'uninitialized' ;
599cee73 103my $Y = 1 ;
0453d815 104my $x = 1 | $a[$Y] ;
4438c4b7 105no warnings 'uninitialized' ;
0453d815
PM
106my $Y = 1 ;
107$x = 1 | $b[$Y] ;
599cee73 108EXPECT
29489e7c 109Use of uninitialized value within @a in bitwise or (|) at - line 4.
599cee73
PM
110########
111# sv.c
4438c4b7 112use warnings 'uninitialized' ;
a1afd104
DM
113my $Y = 1 ;
114my $x = 1 & $a[$Y] ;
115no warnings 'uninitialized' ;
116my $Y = 1 ;
117$x = 1 & $b[$Y] ;
118EXPECT
29489e7c 119Use of uninitialized value within @a in bitwise and (&) at - line 4.
a1afd104
DM
120########
121# sv.c
122use warnings 'uninitialized' ;
123my $Y = 1 ;
124my $x = ~$a[$Y] ;
125no warnings 'uninitialized' ;
126my $Y = 1 ;
127$x = ~$b[$Y] ;
128EXPECT
29489e7c 129Use of uninitialized value within @a in 1's complement (~) at - line 4.
a1afd104
DM
130########
131# sv.c
132use warnings 'uninitialized' ;
599cee73 133my $x *= 1 ; # d
4438c4b7 134no warnings 'uninitialized' ;
0453d815 135my $y *= 1 ; # d
599cee73 136EXPECT
29489e7c 137Use of uninitialized value $x in multiplication (*) at - line 3.
599cee73
PM
138########
139# sv.c
4438c4b7 140use warnings 'uninitialized' ;
599cee73 141$x = 1 + $a[0] ; # e
4438c4b7 142no warnings 'uninitialized' ;
0453d815 143$x = 1 + $b[0] ; # e
599cee73 144EXPECT
29489e7c 145Use of uninitialized value $a[0] in addition (+) at - line 3.
599cee73
PM
146########
147# sv.c (sv_2nv)
148package fred ;
149sub TIESCALAR { my $x ; bless \$x}
150sub FETCH { return undef }
151sub STORE { return 1 }
152package main ;
153tie $A, 'fred' ;
4438c4b7 154use warnings 'uninitialized' ;
599cee73 155$A *= 2 ;
4438c4b7 156no warnings 'uninitialized' ;
0453d815 157$A *= 2 ;
599cee73 158EXPECT
29489e7c 159Use of uninitialized value $A in multiplication (*) at - line 9.
599cee73
PM
160########
161# sv.c
4438c4b7 162use warnings 'uninitialized' ;
599cee73 163$x = $y + 1 ; # f
4438c4b7 164no warnings 'uninitialized' ;
0453d815 165$x = $z + 1 ; # f
599cee73 166EXPECT
29489e7c 167Use of uninitialized value $y in addition (+) at - line 3.
599cee73
PM
168########
169# sv.c
4438c4b7 170use warnings 'uninitialized' ;
599cee73 171$x = chop undef ; # g
4438c4b7 172no warnings 'uninitialized' ;
0453d815 173$x = chop undef ; # g
599cee73 174EXPECT
b0c98cec 175Modification of a read-only value attempted at - line 3.
599cee73
PM
176########
177# sv.c
4438c4b7 178use warnings 'uninitialized' ;
599cee73 179$x = chop $y ; # h
4438c4b7 180no warnings 'uninitialized' ;
0453d815 181$x = chop $z ; # h
599cee73 182EXPECT
29489e7c 183Use of uninitialized value $y in scalar chop at - line 3.
599cee73
PM
184########
185# sv.c (sv_2pv)
186package fred ;
187sub TIESCALAR { my $x ; bless \$x}
188sub FETCH { return undef }
189sub STORE { return 1 }
190package main ;
191tie $A, 'fred' ;
4438c4b7 192use warnings 'uninitialized' ;
599cee73
PM
193$B = "" ;
194$B .= $A ;
4438c4b7 195no warnings 'uninitialized' ;
0453d815
PM
196$C = "" ;
197$C .= $A ;
599cee73 198EXPECT
29489e7c 199Use of uninitialized value $A in concatenation (.) or string at - line 10.
599cee73 200########
531d2254
MS
201# perlbug 20011116.125
202use warnings 'uninitialized';
203$a = undef;
204$foo = join '', $a, "\n";
205$foo = "$a\n";
206$foo = "a:$a\n";
207EXPECT
29489e7c
DM
208Use of uninitialized value $a in join or string at - line 4.
209Use of uninitialized value $a in concatenation (.) or string at - line 5.
210Use of uninitialized value $a in concatenation (.) or string at - line 6.
531d2254 211########
6d1f0892
FC
212# [perl #72090]
213use warnings 'uninitialized';
214$a = @$a > 0;
215EXPECT
216Use of uninitialized value $a in array dereference at - line 3.
217Use of uninitialized value in numeric gt (>) at - line 3.
218########
599cee73 219# sv.c
4438c4b7 220use warnings 'numeric' ;
599cee73
PM
221sub TIESCALAR{bless[]} ;
222sub FETCH {"def"} ;
223tie $a,"main" ;
0453d815 224my $b = 1 + $a;
4438c4b7 225no warnings 'numeric' ;
0453d815 226my $c = 1 + $a;
599cee73 227EXPECT
42d38218 228Argument "def" isn't numeric in addition (+) at - line 6.
599cee73
PM
229########
230# sv.c
4438c4b7 231use warnings 'numeric' ;
599cee73 232my $x = 1 + "def" ;
4438c4b7 233no warnings 'numeric' ;
0453d815 234my $z = 1 + "def" ;
599cee73 235EXPECT
42d38218 236Argument "def" isn't numeric in addition (+) at - line 3.
599cee73
PM
237########
238# sv.c
4438c4b7 239use warnings 'numeric' ;
599cee73
PM
240my $a = "def" ;
241my $x = 1 + $a ;
4438c4b7 242no warnings 'numeric' ;
0453d815 243my $y = 1 + $a ;
599cee73 244EXPECT
42d38218 245Argument "def" isn't numeric in addition (+) at - line 4.
599cee73
PM
246########
247# sv.c
4438c4b7 248use warnings 'numeric' ; use integer ;
599cee73
PM
249my $a = "def" ;
250my $x = 1 + $a ;
4438c4b7 251no warnings 'numeric' ;
0453d815 252my $z = 1 + $a ;
599cee73 253EXPECT
42d38218 254Argument "def" isn't numeric in integer addition (+) at - line 4.
599cee73
PM
255########
256# sv.c
4438c4b7 257use warnings 'numeric' ;
599cee73 258my $x = 1 & "def" ;
4438c4b7 259no warnings 'numeric' ;
0453d815 260my $z = 1 & "def" ;
599cee73 261EXPECT
42d38218 262Argument "def" isn't numeric in bitwise and (&) at - line 3.
599cee73
PM
263########
264# sv.c
59bb5845
RB
265use warnings 'numeric' ;
266my $x = pack i => "def" ;
267no warnings 'numeric' ;
268my $z = pack i => "def" ;
269EXPECT
270Argument "def" isn't numeric in pack at - line 3.
271########
272# sv.c
273use warnings 'numeric' ;
274my $a = "d\0f" ;
275my $x = 1 + $a ;
276no warnings 'numeric' ;
277my $z = 1 + $a ;
278EXPECT
279Argument "d\0f" isn't numeric in addition (+) at - line 4.
280########
281# sv.c
4438c4b7 282use warnings 'redefine' ;
599cee73
PM
283sub fred {}
284sub joe {}
285*fred = \&joe ;
4438c4b7 286no warnings 'redefine' ;
0453d815
PM
287sub jim {}
288*jim = \&joe ;
599cee73 289EXPECT
910764e6 290Subroutine main::fred redefined at - line 5.
599cee73
PM
291########
292# sv.c
4438c4b7 293use warnings 'printf' ;
3eeba6fb 294open F, ">".($^O eq 'VMS'? 'NL:' : '/dev/null') ;
cf2093f6
JH
295printf F "%z\n" ;
296my $a = sprintf "%z" ;
599cee73
PM
297printf F "%" ;
298$a = sprintf "%" ;
299printf F "%\x02" ;
300$a = sprintf "%\x02" ;
1d1ac7bc
MHM
301printf F "%llz" ;
302$a = sprintf "%llz" ;
303printf F "%25llz" ;
304$a = sprintf "%25llz" ;
305printf F "%+2Lz" ;
306$a = sprintf "%+2Lz" ;
307printf F "%+2ll" ;
308$a = sprintf "%+2ll" ;
309printf F "%+2L\x03" ;
310$a = sprintf "%+2L\x03" ;
4438c4b7 311no warnings 'printf' ;
cf2093f6
JH
312printf F "%z\n" ;
313$a = sprintf "%z" ;
0453d815
PM
314printf F "%" ;
315$a = sprintf "%" ;
316printf F "%\x02" ;
317$a = sprintf "%\x02" ;
1d1ac7bc
MHM
318printf F "%llz" ;
319$a = sprintf "%llz" ;
320printf F "%25llz" ;
321$a = sprintf "%25llz" ;
322printf F "%+2Lz" ;
323$a = sprintf "%+2Lz" ;
324printf F "%+2ll" ;
325$a = sprintf "%+2ll" ;
326printf F "%+2L\x03" ;
327$a = sprintf "%+2L\x03" ;
599cee73 328EXPECT
cf2093f6 329Invalid conversion in printf: "%z" at - line 4.
fc7325bb 330Invalid conversion in sprintf: "%z" at - line 5.
599cee73 331Invalid conversion in printf: end of string at - line 6.
fc7325bb 332Invalid conversion in sprintf: end of string at - line 7.
599cee73 333Invalid conversion in printf: "%\002" at - line 8.
fc7325bb 334Invalid conversion in sprintf: "%\002" at - line 9.
1d1ac7bc
MHM
335Invalid conversion in printf: "%llz" at - line 10.
336Invalid conversion in sprintf: "%llz" at - line 11.
337Invalid conversion in printf: "%25llz" at - line 12.
338Invalid conversion in sprintf: "%25llz" at - line 13.
339Invalid conversion in printf: "%+2Lz" at - line 14.
340Invalid conversion in sprintf: "%+2Lz" at - line 15.
341Invalid conversion in printf: "%+2ll" at - line 16.
342Invalid conversion in sprintf: "%+2ll" at - line 17.
343Invalid conversion in printf: "%+2L\003" at - line 18.
344Invalid conversion in sprintf: "%+2L\003" at - line 19.
599cee73
PM
345########
346# sv.c
e476b1b5 347use warnings 'misc' ;
599cee73 348*a = undef ;
e476b1b5 349no warnings 'misc' ;
0453d815 350*b = undef ;
599cee73
PM
351EXPECT
352Undefined value assigned to typeglob at - line 3.
0453d815
PM
353########
354# sv.c
94463019
JH
355use warnings 'numeric' ;
356$a = "\x{100}\x{200}" * 42;
357no warnings 'numeric' ;
358$a = "\x{100}\x{200}" * 42;
359EXPECT
360Argument "\x{100}\x{200}" isn't numeric in multiplication (*) at - line 3.
8eb28a70
JH
361########
362# sv.c
363use warnings 'numeric' ;
364$a = "\x{100}\x{200}"; $a = -$a;
365no warnings 'numeric' ;
366$a = "\x{100}\x{200}"; $a = -$a;
367EXPECT
368Argument "\x{100}\x{200}" isn't numeric in negation (-) at - line 3.