This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
handle magic in multideref "unit val" var names
[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
8b6051f1
FC
37 vector argument not supported with alpha versions
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
29489e7c 61Use of uninitialized value $a[0] 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
29489e7c 76Use of uninitialized value $A 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
29489e7c 85Use of uninitialized value $x 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
29489e7c 101Use of uninitialized value $A 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
29489e7c 111Use of uninitialized value within @a 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
29489e7c 121Use of uninitialized value within @a in bitwise and (&) at - line 4.
a1afd104
DM
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
29489e7c 131Use of uninitialized value within @a in 1's complement (~) at - line 4.
a1afd104
DM
132########
133# sv.c
134use warnings 'uninitialized' ;
599cee73 135my $x *= 1 ; # d
4438c4b7 136no warnings 'uninitialized' ;
0453d815 137my $y *= 1 ; # d
599cee73 138EXPECT
29489e7c 139Use of uninitialized value $x 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
29489e7c 147Use of uninitialized value $a[0] 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
29489e7c 161Use of uninitialized value $A 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
29489e7c 169Use of uninitialized value $y 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
29489e7c 185Use of uninitialized value $y 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
29489e7c 201Use of uninitialized value $A 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
29489e7c
DM
210Use of uninitialized value $a in join or string at - line 4.
211Use of uninitialized value $a in concatenation (.) or string at - line 5.
212Use of uninitialized value $a in concatenation (.) or string at - line 6.
531d2254 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') ;
bc6e9114
CS
290printf F "%y\n" ;
291my $a = sprintf "%y" ;
599cee73
PM
292printf F "%" ;
293$a = sprintf "%" ;
294printf F "%\x02" ;
295$a = sprintf "%\x02" ;
bc6e9114
CS
296printf F "%lly" ;
297$a = sprintf "%lly" ;
298printf F "%25lly" ;
299$a = sprintf "%25lly" ;
300printf F "%+2Ly" ;
301$a = sprintf "%+2Ly" ;
1d1ac7bc
MHM
302printf F "%+2ll" ;
303$a = sprintf "%+2ll" ;
304printf F "%+2L\x03" ;
305$a = sprintf "%+2L\x03" ;
4438c4b7 306no warnings 'printf' ;
bc6e9114
CS
307printf F "%y\n" ;
308$a = sprintf "%y" ;
0453d815
PM
309printf F "%" ;
310$a = sprintf "%" ;
311printf F "%\x02" ;
312$a = sprintf "%\x02" ;
bc6e9114
CS
313printf F "%lly" ;
314$a = sprintf "%lly" ;
315printf F "%25lly" ;
316$a = sprintf "%25lly" ;
317printf F "%+2Ly" ;
318$a = sprintf "%+2Ly" ;
1d1ac7bc
MHM
319printf F "%+2ll" ;
320$a = sprintf "%+2ll" ;
321printf F "%+2L\x03" ;
322$a = sprintf "%+2L\x03" ;
599cee73 323EXPECT
bc6e9114
CS
324Invalid conversion in printf: "%y" at - line 4.
325Invalid conversion in sprintf: "%y" at - line 5.
599cee73 326Invalid conversion in printf: end of string at - line 6.
fc7325bb 327Invalid conversion in sprintf: end of string at - line 7.
599cee73 328Invalid conversion in printf: "%\002" at - line 8.
fc7325bb 329Invalid conversion in sprintf: "%\002" at - line 9.
bc6e9114
CS
330Invalid conversion in printf: "%lly" at - line 10.
331Invalid conversion in sprintf: "%lly" at - line 11.
332Invalid conversion in printf: "%25lly" at - line 12.
333Invalid conversion in sprintf: "%25lly" at - line 13.
334Invalid conversion in printf: "%+2Ly" at - line 14.
335Invalid conversion in sprintf: "%+2Ly" at - line 15.
1d1ac7bc
MHM
336Invalid conversion in printf: "%+2ll" at - line 16.
337Invalid conversion in sprintf: "%+2ll" at - line 17.
338Invalid conversion in printf: "%+2L\003" at - line 18.
339Invalid conversion in sprintf: "%+2L\003" at - line 19.
599cee73
PM
340########
341# sv.c
e476b1b5 342use warnings 'misc' ;
599cee73 343*a = undef ;
e476b1b5 344no warnings 'misc' ;
0453d815 345*b = undef ;
599cee73
PM
346EXPECT
347Undefined value assigned to typeglob at - line 3.
0453d815
PM
348########
349# sv.c
94463019
JH
350use warnings 'numeric' ;
351$a = "\x{100}\x{200}" * 42;
352no warnings 'numeric' ;
353$a = "\x{100}\x{200}" * 42;
354EXPECT
355Argument "\x{100}\x{200}" isn't numeric in multiplication (*) at - line 3.
8eb28a70
JH
356########
357# sv.c
358use warnings 'numeric' ;
359$a = "\x{100}\x{200}"; $a = -$a;
360no warnings 'numeric' ;
361$a = "\x{100}\x{200}"; $a = -$a;
362EXPECT
363Argument "\x{100}\x{200}" isn't numeric in negation (-) at - line 3.
012bcf7e
BF
364########
365# sv.c
37b8cdd1
RGS
366use warnings 'numeric' ;
367$a = "\x{100}\x{1000}" x 10; $b = $a < 1;
368no warnings 'numeric' ;
369$a = "\x{100}\x{1000}" x 10; $b = $a < 1;
370EXPECT
371Argument "\x{100}\x{1000}\x{100}\x{1000}\x{100}..." isn't numeric in numeric lt (<) at - line 3.
372########
373# sv.c
012bcf7e
BF
374use warnings 'redefine' ;
375use utf8;
376use open qw( :utf8 :std );
377sub frèd {}
378sub jòè {}
379*frèd = \&jòè;
380no warnings 'redefine' ;
381sub jìm {}
382*jìm = \&jòè ;
383EXPECT
384Subroutine main::frèd redefined at - line 7.
385########
386# sv.c
387use warnings 'redefine' ;
388use utf8;
389use open qw( :utf8 :std );
390sub f렏 {}
391sub 조Ȩ {}
392*f렏 = \&조Ȩ ;
393no warnings 'redefine' ;
394sub 짐 {}
395*짐 = \&조Ȩ ;
396EXPECT
397Subroutine main::f렏 redefined at - line 7.
8b6051f1
FC
398########
399# sv.c
3f7602fa
TC
400my $x = "a_c";
401++$x;
402use warnings "numeric";
403$x = "a_c"; ++$x;
404$x = ${ qr/abc/ }; ++$x;
405$x = "123x"; ++$x;
406$x = "123e"; ++$x;
407$x = 0; ++$x; # none of these should warn
408$x = "ABC"; ++$x;
409$x = "ABC123"; ++$x;
410$x = " +10"; ++$x;
411EXPECT
0c7e610f
JH
412Argument "a_c" isn't numeric in preincrement (++) at - line 5.
413Argument "(?^:abc)" isn't numeric in preincrement (++) at - line 6.
3f7602fa
TC
414Argument "123x" isn't numeric in preincrement (++) at - line 7.
415Argument "123e" isn't numeric in preincrement (++) at - line 8.