This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perlapi: Fix grammar
[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########
ee95e30c 203# perlbug 20011116.125 (#7917)
531d2254
MS
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 ;
523e5ba8 344(*c) = ();
e476b1b5 345no warnings 'misc' ;
0453d815 346*b = undef ;
523e5ba8 347(*d) = ();
599cee73
PM
348EXPECT
349Undefined value assigned to typeglob at - line 3.
523e5ba8 350Undefined value assigned to typeglob at - line 4.
0453d815
PM
351########
352# sv.c
94463019
JH
353use warnings 'numeric' ;
354$a = "\x{100}\x{200}" * 42;
355no warnings 'numeric' ;
356$a = "\x{100}\x{200}" * 42;
357EXPECT
358Argument "\x{100}\x{200}" isn't numeric in multiplication (*) at - line 3.
8eb28a70
JH
359########
360# sv.c
361use warnings 'numeric' ;
362$a = "\x{100}\x{200}"; $a = -$a;
363no warnings 'numeric' ;
364$a = "\x{100}\x{200}"; $a = -$a;
365EXPECT
366Argument "\x{100}\x{200}" isn't numeric in negation (-) at - line 3.
012bcf7e
BF
367########
368# sv.c
37b8cdd1
RGS
369use warnings 'numeric' ;
370$a = "\x{100}\x{1000}" x 10; $b = $a < 1;
371no warnings 'numeric' ;
372$a = "\x{100}\x{1000}" x 10; $b = $a < 1;
373EXPECT
374Argument "\x{100}\x{1000}\x{100}\x{1000}\x{100}..." isn't numeric in numeric lt (<) at - line 3.
375########
376# sv.c
012bcf7e
BF
377use warnings 'redefine' ;
378use utf8;
379use open qw( :utf8 :std );
380sub frèd {}
381sub jòè {}
382*frèd = \&jòè;
383no warnings 'redefine' ;
384sub jìm {}
385*jìm = \&jòè ;
386EXPECT
387Subroutine main::frèd redefined at - line 7.
388########
389# sv.c
390use warnings 'redefine' ;
391use utf8;
392use open qw( :utf8 :std );
393sub f렏 {}
394sub 조Ȩ {}
395*f렏 = \&조Ȩ ;
396no warnings 'redefine' ;
397sub 짐 {}
398*짐 = \&조Ȩ ;
399EXPECT
400Subroutine main::f렏 redefined at - line 7.
8b6051f1
FC
401########
402# sv.c
3f7602fa
TC
403my $x = "a_c";
404++$x;
405use warnings "numeric";
406$x = "a_c"; ++$x;
407$x = ${ qr/abc/ }; ++$x;
408$x = "123x"; ++$x;
409$x = "123e"; ++$x;
410$x = 0; ++$x; # none of these should warn
411$x = "ABC"; ++$x;
412$x = "ABC123"; ++$x;
413$x = " +10"; ++$x;
414EXPECT
0c7e610f
JH
415Argument "a_c" isn't numeric in preincrement (++) at - line 5.
416Argument "(?^:abc)" isn't numeric in preincrement (++) at - line 6.
3f7602fa
TC
417Argument "123x" isn't numeric in preincrement (++) at - line 7.
418Argument "123e" isn't numeric in preincrement (++) at - line 8.
fc0fe26a
DM
419########
420# RT #128257 This used to SEGV
421use warnings;
422sub Foo::f {}
423undef *Foo::;
424*Foo::f =sub {};
425EXPECT
426Subroutine f redefined at - line 5.