This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move a test from t/lib/warnings/sv to .../9uninit
[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########
599cee73 212# sv.c
4438c4b7 213use warnings 'numeric' ;
599cee73
PM
214sub TIESCALAR{bless[]} ;
215sub FETCH {"def"} ;
216tie $a,"main" ;
0453d815 217my $b = 1 + $a;
4438c4b7 218no warnings 'numeric' ;
0453d815 219my $c = 1 + $a;
599cee73 220EXPECT
42d38218 221Argument "def" isn't numeric in addition (+) at - line 6.
599cee73
PM
222########
223# sv.c
4438c4b7 224use warnings 'numeric' ;
599cee73 225my $x = 1 + "def" ;
4438c4b7 226no warnings 'numeric' ;
0453d815 227my $z = 1 + "def" ;
599cee73 228EXPECT
42d38218 229Argument "def" isn't numeric in addition (+) at - line 3.
599cee73
PM
230########
231# sv.c
4438c4b7 232use warnings 'numeric' ;
599cee73
PM
233my $a = "def" ;
234my $x = 1 + $a ;
4438c4b7 235no warnings 'numeric' ;
0453d815 236my $y = 1 + $a ;
599cee73 237EXPECT
42d38218 238Argument "def" isn't numeric in addition (+) at - line 4.
599cee73
PM
239########
240# sv.c
4438c4b7 241use warnings 'numeric' ; use integer ;
599cee73
PM
242my $a = "def" ;
243my $x = 1 + $a ;
4438c4b7 244no warnings 'numeric' ;
0453d815 245my $z = 1 + $a ;
599cee73 246EXPECT
42d38218 247Argument "def" isn't numeric in integer addition (+) at - line 4.
599cee73
PM
248########
249# sv.c
4438c4b7 250use warnings 'numeric' ;
599cee73 251my $x = 1 & "def" ;
4438c4b7 252no warnings 'numeric' ;
0453d815 253my $z = 1 & "def" ;
599cee73 254EXPECT
42d38218 255Argument "def" isn't numeric in bitwise and (&) at - line 3.
599cee73
PM
256########
257# sv.c
59bb5845
RB
258use warnings 'numeric' ;
259my $x = pack i => "def" ;
260no warnings 'numeric' ;
261my $z = pack i => "def" ;
262EXPECT
263Argument "def" isn't numeric in pack at - line 3.
264########
265# sv.c
266use warnings 'numeric' ;
267my $a = "d\0f" ;
268my $x = 1 + $a ;
269no warnings 'numeric' ;
270my $z = 1 + $a ;
271EXPECT
272Argument "d\0f" isn't numeric in addition (+) at - line 4.
273########
274# sv.c
4438c4b7 275use warnings 'redefine' ;
599cee73
PM
276sub fred {}
277sub joe {}
278*fred = \&joe ;
4438c4b7 279no warnings 'redefine' ;
0453d815
PM
280sub jim {}
281*jim = \&joe ;
599cee73 282EXPECT
910764e6 283Subroutine main::fred redefined at - line 5.
599cee73
PM
284########
285# sv.c
4438c4b7 286use warnings 'printf' ;
3eeba6fb 287open F, ">".($^O eq 'VMS'? 'NL:' : '/dev/null') ;
bc6e9114
CS
288printf F "%y\n" ;
289my $a = sprintf "%y" ;
599cee73
PM
290printf F "%" ;
291$a = sprintf "%" ;
292printf F "%\x02" ;
293$a = sprintf "%\x02" ;
bc6e9114
CS
294printf F "%lly" ;
295$a = sprintf "%lly" ;
296printf F "%25lly" ;
297$a = sprintf "%25lly" ;
298printf F "%+2Ly" ;
299$a = sprintf "%+2Ly" ;
1d1ac7bc
MHM
300printf F "%+2ll" ;
301$a = sprintf "%+2ll" ;
302printf F "%+2L\x03" ;
303$a = sprintf "%+2L\x03" ;
4438c4b7 304no warnings 'printf' ;
bc6e9114
CS
305printf F "%y\n" ;
306$a = sprintf "%y" ;
0453d815
PM
307printf F "%" ;
308$a = sprintf "%" ;
309printf F "%\x02" ;
310$a = sprintf "%\x02" ;
bc6e9114
CS
311printf F "%lly" ;
312$a = sprintf "%lly" ;
313printf F "%25lly" ;
314$a = sprintf "%25lly" ;
315printf F "%+2Ly" ;
316$a = sprintf "%+2Ly" ;
1d1ac7bc
MHM
317printf F "%+2ll" ;
318$a = sprintf "%+2ll" ;
319printf F "%+2L\x03" ;
320$a = sprintf "%+2L\x03" ;
599cee73 321EXPECT
bc6e9114
CS
322Invalid conversion in printf: "%y" at - line 4.
323Invalid conversion in sprintf: "%y" at - line 5.
599cee73 324Invalid conversion in printf: end of string at - line 6.
fc7325bb 325Invalid conversion in sprintf: end of string at - line 7.
599cee73 326Invalid conversion in printf: "%\002" at - line 8.
fc7325bb 327Invalid conversion in sprintf: "%\002" at - line 9.
bc6e9114
CS
328Invalid conversion in printf: "%lly" at - line 10.
329Invalid conversion in sprintf: "%lly" at - line 11.
330Invalid conversion in printf: "%25lly" at - line 12.
331Invalid conversion in sprintf: "%25lly" at - line 13.
332Invalid conversion in printf: "%+2Ly" at - line 14.
333Invalid conversion in sprintf: "%+2Ly" at - line 15.
1d1ac7bc
MHM
334Invalid conversion in printf: "%+2ll" at - line 16.
335Invalid conversion in sprintf: "%+2ll" at - line 17.
336Invalid conversion in printf: "%+2L\003" at - line 18.
337Invalid conversion in sprintf: "%+2L\003" at - line 19.
599cee73
PM
338########
339# sv.c
e476b1b5 340use warnings 'misc' ;
599cee73 341*a = undef ;
e476b1b5 342no warnings 'misc' ;
0453d815 343*b = undef ;
599cee73
PM
344EXPECT
345Undefined value assigned to typeglob at - line 3.
0453d815
PM
346########
347# sv.c
94463019
JH
348use warnings 'numeric' ;
349$a = "\x{100}\x{200}" * 42;
350no warnings 'numeric' ;
351$a = "\x{100}\x{200}" * 42;
352EXPECT
353Argument "\x{100}\x{200}" isn't numeric in multiplication (*) at - line 3.
8eb28a70
JH
354########
355# sv.c
356use warnings 'numeric' ;
357$a = "\x{100}\x{200}"; $a = -$a;
358no warnings 'numeric' ;
359$a = "\x{100}\x{200}"; $a = -$a;
360EXPECT
361Argument "\x{100}\x{200}" isn't numeric in negation (-) at - line 3.
012bcf7e
BF
362########
363# sv.c
364use warnings 'redefine' ;
365use utf8;
366use open qw( :utf8 :std );
367sub frèd {}
368sub jòè {}
369*frèd = \&jòè;
370no warnings 'redefine' ;
371sub jìm {}
372*jìm = \&jòè ;
373EXPECT
374Subroutine main::frèd redefined at - line 7.
375########
376# sv.c
377use warnings 'redefine' ;
378use utf8;
379use open qw( :utf8 :std );
380sub f렏 {}
381sub 조Ȩ {}
382*f렏 = \&조Ȩ ;
383no warnings 'redefine' ;
384sub 짐 {}
385*짐 = \&조Ȩ ;
386EXPECT
387Subroutine main::f렏 redefined at - line 7.