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