xref: /openbsd/gnu/usr.bin/perl/t/lib/warnings/sv (revision eac174f2)
1  sv.c
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
35  Reference is already weak			[Perl_sv_rvweaken] <<TODO
36
37  vector argument not supported with alpha versions
38
39  Mandatory Warnings
40  ------------------
41  Malformed UTF-8 character [sv_pos_b2u] (not tested: difficult to produce
42                                          with perl now)
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
52
53__END__
54# sv.c
55use integer ;
56use warnings 'uninitialized' ;
57$x = 1 + $a[0] ; # a
58no warnings 'uninitialized' ;
59$x = 1 + $b[0] ; # a
60EXPECT
61Use of uninitialized value $a[0] in integer addition (+) at - line 4.
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 ;
71use warnings 'uninitialized' ;
72$A *= 2 ;
73no warnings 'uninitialized' ;
74$A *= 2 ;
75EXPECT
76Use of uninitialized value $A in integer multiplication (*) at - line 10.
77########
78# sv.c
79use integer ;
80use warnings 'uninitialized' ;
81my $x *= 2 ; #b
82no warnings 'uninitialized' ;
83my $y *= 2 ; #b
84EXPECT
85Use of uninitialized value $x in integer multiplication (*) at - line 4.
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' ;
94use warnings 'uninitialized' ;
95$B = 0 ;
96$B |= $A ;
97no warnings 'uninitialized' ;
98$B = 0 ;
99$B |= $A ;
100EXPECT
101Use of uninitialized value $A in bitwise or (|) at - line 10.
102########
103# sv.c
104use warnings 'uninitialized' ;
105my $Y = 1 ;
106my $x = 1 | $a[$Y] ;
107no warnings 'uninitialized' ;
108my $Y = 1 ;
109$x = 1 | $b[$Y] ;
110EXPECT
111Use of uninitialized value $a[1] in bitwise or (|) at - line 4.
112########
113# sv.c
114use warnings 'uninitialized' ;
115my $Y = 1 ;
116my $x = 1 & $a[$Y] ;
117no warnings 'uninitialized' ;
118my $Y = 1 ;
119$x = 1 & $b[$Y] ;
120EXPECT
121Use of uninitialized value $a[1] 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 $a[1] in 1's complement (~) at - line 4.
132########
133# sv.c
134use warnings 'uninitialized' ;
135my $x *= 1 ; # d
136no warnings 'uninitialized' ;
137my $y *= 1 ; # d
138EXPECT
139Use of uninitialized value $x in multiplication (*) at - line 3.
140########
141# sv.c
142use warnings 'uninitialized' ;
143$x = 1 + $a[0] ; # e
144no warnings 'uninitialized' ;
145$x = 1 + $b[0] ; # e
146EXPECT
147Use of uninitialized value $a[0] in addition (+) at - line 3.
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' ;
156use warnings 'uninitialized' ;
157$A *= 2 ;
158no warnings 'uninitialized' ;
159$A *= 2 ;
160EXPECT
161Use of uninitialized value $A in multiplication (*) at - line 9.
162########
163# sv.c
164use warnings 'uninitialized' ;
165$x = $y + 1 ; # f
166no warnings 'uninitialized' ;
167$x = $z + 1 ; # f
168EXPECT
169Use of uninitialized value $y in addition (+) at - line 3.
170########
171# sv.c
172use warnings 'uninitialized' ;
173$x = chop undef ; # g
174no warnings 'uninitialized' ;
175$x = chop undef ; # g
176EXPECT
177Modification of a read-only value attempted at - line 3.
178########
179# sv.c
180use warnings 'uninitialized' ;
181$x = chop $y ; # h
182no warnings 'uninitialized' ;
183$x = chop $z ; # h
184EXPECT
185Use of uninitialized value $y in scalar chop at - line 3.
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' ;
194use warnings 'uninitialized' ;
195$B = "" ;
196$B .= $A ;
197no warnings 'uninitialized' ;
198$C = "" ;
199$C .= $A ;
200EXPECT
201Use of uninitialized value $A in concatenation (.) or string at - line 10.
202########
203# perlbug 20011116.125 (#7917)
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 $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.
213########
214# NAME https://github.com/Perl/perl5/issues/19147
215use warnings 'uninitialized';
216my %x;
217my @z;
218my $y;
219-$x{$y};
220-$z[$y];
221EXPECT
222Use of uninitialized value $y in hash element at - line 5.
223Use of uninitialized value $x{""} in negation (-) at - line 5.
224Use of uninitialized value $y in array element at - line 6.
225Use of uninitialized value $z[0] in negation (-) at - line 6.
226########
227# sv.c
228use warnings 'numeric' ;
229sub TIESCALAR{bless[]} ;
230sub FETCH {"def"} ;
231tie $a,"main" ;
232my $b = 1 + $a;
233no warnings 'numeric' ;
234my $c = 1 + $a;
235EXPECT
236Argument "def" isn't numeric in addition (+) at - line 6.
237########
238# sv.c
239use warnings 'numeric' ;
240my $x = 1 + "def" ;
241no warnings 'numeric' ;
242my $z = 1 + "def" ;
243EXPECT
244Argument "def" isn't numeric in addition (+) at - line 3.
245########
246# sv.c
247use warnings 'numeric' ;
248my $a = "def" ;
249my $x = 1 + $a ;
250no warnings 'numeric' ;
251my $y = 1 + $a ;
252EXPECT
253Argument "def" isn't numeric in addition (+) at - line 4.
254########
255# sv.c
256use warnings 'numeric' ; use integer ;
257my $a = "def" ;
258my $x = 1 + $a ;
259no warnings 'numeric' ;
260my $z = 1 + $a ;
261EXPECT
262Argument "def" isn't numeric in integer addition (+) at - line 4.
263########
264# sv.c
265use warnings 'numeric' ;
266my $x = 1 & "def" ;
267no warnings 'numeric' ;
268my $z = 1 & "def" ;
269EXPECT
270Argument "def" isn't numeric in bitwise and (&) at - line 3.
271########
272# sv.c
273use warnings 'numeric' ;
274my $x = pack i => "def" ;
275no warnings 'numeric' ;
276my $z = pack i => "def" ;
277EXPECT
278Argument "def" isn't numeric in pack at - line 3.
279########
280# sv.c
281use warnings 'numeric' ;
282my $a = "d\0f" ;
283my $x = 1 + $a ;
284no warnings 'numeric' ;
285my $z = 1 + $a ;
286EXPECT
287Argument "d\0f" isn't numeric in addition (+) at - line 4.
288########
289# sv.c
290use warnings 'redefine' ;
291sub fred {}
292sub joe {}
293*fred = \&joe ;
294no warnings 'redefine' ;
295sub jim {}
296*jim = \&joe ;
297EXPECT
298Subroutine main::fred redefined at - line 5.
299########
300# sv.c
301use warnings 'printf' ;
302open F, ">".($^O eq 'VMS'? 'NL:' : '/dev/null') ;
303printf F "%y\n" ;
304my $a = sprintf "%y" ;
305printf F "%" ;
306$a = sprintf "%" ;
307printf F "%\x02" ;
308$a = sprintf "%\x02" ;
309printf F "%lly" ;
310$a = sprintf "%lly" ;
311printf F "%25lly" ;
312$a = sprintf "%25lly" ;
313printf F "%+2Ly" ;
314$a = sprintf "%+2Ly" ;
315printf F "%+2ll" ;
316$a = sprintf "%+2ll" ;
317printf F "%+2L\x03" ;
318$a = sprintf "%+2L\x03" ;
319no warnings 'printf' ;
320printf F "%y\n" ;
321$a = sprintf "%y" ;
322printf F "%" ;
323$a = sprintf "%" ;
324printf F "%\x02" ;
325$a = sprintf "%\x02" ;
326printf F "%lly" ;
327$a = sprintf "%lly" ;
328printf F "%25lly" ;
329$a = sprintf "%25lly" ;
330printf F "%+2Ly" ;
331$a = sprintf "%+2Ly" ;
332printf F "%+2ll" ;
333$a = sprintf "%+2ll" ;
334printf F "%+2L\x03" ;
335$a = sprintf "%+2L\x03" ;
336EXPECT
337Invalid conversion in printf: "%y" at - line 4.
338Invalid conversion in sprintf: "%y" at - line 5.
339Invalid conversion in printf: end of string at - line 6.
340Invalid conversion in sprintf: end of string at - line 7.
341Invalid conversion in printf: "%\002" at - line 8.
342Invalid conversion in sprintf: "%\002" at - line 9.
343Invalid conversion in printf: "%lly" at - line 10.
344Invalid conversion in sprintf: "%lly" at - line 11.
345Invalid conversion in printf: "%25lly" at - line 12.
346Invalid conversion in sprintf: "%25lly" at - line 13.
347Invalid conversion in printf: "%+2Ly" at - line 14.
348Invalid conversion in sprintf: "%+2Ly" at - line 15.
349Invalid conversion in printf: "%+2ll" at - line 16.
350Invalid conversion in sprintf: "%+2ll" at - line 17.
351Invalid conversion in printf: "%+2L\003" at - line 18.
352Invalid conversion in sprintf: "%+2L\003" at - line 19.
353########
354# sv.c
355use warnings 'misc' ;
356*a = undef ;
357(*c) = ();
358no warnings 'misc' ;
359*b = undef ;
360(*d) = ();
361EXPECT
362Undefined value assigned to typeglob at - line 3.
363Undefined value assigned to typeglob at - line 4.
364########
365# sv.c
366use warnings 'numeric' ;
367$a = "\x{100}\x{200}" * 42;
368no warnings 'numeric' ;
369$a = "\x{100}\x{200}" * 42;
370EXPECT
371Argument "\x{100}\x{200}" isn't numeric in multiplication (*) at - line 3.
372########
373# sv.c
374use warnings 'numeric' ;
375$a = "\x{100}\x{200}"; $a = -$a;
376no warnings 'numeric' ;
377$a = "\x{100}\x{200}"; $a = -$a;
378EXPECT
379Argument "\x{100}\x{200}" isn't numeric in negation (-) at - line 3.
380########
381# sv.c
382use warnings 'numeric' ;
383$a = "\x{100}\x{1000}" x 10; $b = $a < 1;
384no warnings 'numeric' ;
385$a = "\x{100}\x{1000}" x 10; $b = $a < 1;
386EXPECT
387Argument "\x{100}\x{1000}\x{100}\x{1000}\x{100}..." isn't numeric in numeric lt (<) at - line 3.
388########
389# sv.c
390use warnings 'redefine' ;
391use utf8;
392use open qw( :utf8 :std );
393sub frèd {}
394sub jòè {}
395*frèd = \&jòè;
396no warnings 'redefine' ;
397sub jìm {}
398*jìm = \&jòè ;
399EXPECT
400Subroutine main::frèd redefined at - line 7.
401########
402# sv.c
403use warnings 'redefine' ;
404use utf8;
405use open qw( :utf8 :std );
406sub f렏 {}
407sub 조Ȩ {}
408*f렏 = \&조Ȩ ;
409no warnings 'redefine' ;
410sub 짐 {}
411*짐 = \&조Ȩ ;
412EXPECT
413Subroutine main::f렏 redefined at - line 7.
414########
415# sv.c
416my $x = "a_c";
417++$x;
418use warnings "numeric";
419$x = "a_c"; ++$x;
420$x = ${ qr/abc/ }; ++$x;
421$x = "123x"; ++$x;
422$x = "123e"; ++$x;
423$x = 0; ++$x; # none of these should warn
424$x = "ABC"; ++$x;
425$x = "ABC123"; ++$x;
426$x = " +10"; ++$x;
427EXPECT
428Argument "a_c" isn't numeric in preincrement (++) at - line 5.
429Argument "(?^:abc)" isn't numeric in preincrement (++) at - line 6.
430Argument "123x" isn't numeric in preincrement (++) at - line 7.
431Argument "123e" isn't numeric in preincrement (++) at - line 8.
432########
433# RT #128257 This used to SEGV
434use warnings;
435sub Foo::f {}
436undef *Foo::;
437*Foo::f =sub {};
438EXPECT
439Subroutine f redefined at - line 5.
440########
441# sv.c
442use warnings 'redefine';
443sub fred { 1 }
444sub barney() { 2 }
445sub wilma() { 3 }
446# local redefines of subs shouldn't warn...
447local *fred = sub {};
448local(*fred) = sub {};
449# ...unless they're constant
450local *barney = \&fred;
451local(*wilma) = \&fred;
452EXPECT
453Constant subroutine main::barney redefined at - line 10.
454Constant subroutine main::wilma redefined at - line 11.
455