This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Take away the infamous io/dup.t #7.
[perl5.git] / t / pragma / warn / 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 ------------------
41 Malformed UTF-8 character [sv_pos_b2u]
42 my $a = rindex "a\xff bc ", "bc" ;
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
PM
60EXPECT
61Use of uninitialized value 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 ;
4438c4b7 71use warnings 'uninitialized' ;
599cee73 72$A *= 2 ;
4438c4b7 73no warnings 'uninitialized' ;
0453d815 74$A *= 2 ;
599cee73
PM
75EXPECT
76Use of uninitialized value at - line 10.
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
PM
84EXPECT
85Use of uninitialized value 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' ;
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
PM
100EXPECT
101Use of uninitialized value at - line 10.
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
PM
110EXPECT
111Use of uninitialized value at - line 4.
112########
113# sv.c
4438c4b7 114use warnings 'uninitialized' ;
599cee73 115my $x *= 1 ; # d
4438c4b7 116no warnings 'uninitialized' ;
0453d815 117my $y *= 1 ; # d
599cee73
PM
118EXPECT
119Use of uninitialized value at - line 3.
120########
121# sv.c
4438c4b7 122use warnings 'uninitialized' ;
599cee73 123$x = 1 + $a[0] ; # e
4438c4b7 124no warnings 'uninitialized' ;
0453d815 125$x = 1 + $b[0] ; # e
599cee73
PM
126EXPECT
127Use of uninitialized value at - line 3.
128########
129# sv.c (sv_2nv)
130package fred ;
131sub TIESCALAR { my $x ; bless \$x}
132sub FETCH { return undef }
133sub STORE { return 1 }
134package main ;
135tie $A, 'fred' ;
4438c4b7 136use warnings 'uninitialized' ;
599cee73 137$A *= 2 ;
4438c4b7 138no warnings 'uninitialized' ;
0453d815 139$A *= 2 ;
599cee73
PM
140EXPECT
141Use of uninitialized value at - line 9.
142########
143# sv.c
4438c4b7 144use warnings 'uninitialized' ;
599cee73 145$x = $y + 1 ; # f
4438c4b7 146no warnings 'uninitialized' ;
0453d815 147$x = $z + 1 ; # f
599cee73
PM
148EXPECT
149Use of uninitialized value at - line 3.
150########
151# sv.c
4438c4b7 152use warnings 'uninitialized' ;
599cee73 153$x = chop undef ; # g
4438c4b7 154no warnings 'uninitialized' ;
0453d815 155$x = chop undef ; # g
599cee73 156EXPECT
b0c98cec 157Modification of a read-only value attempted at - line 3.
599cee73
PM
158########
159# sv.c
4438c4b7 160use warnings 'uninitialized' ;
599cee73 161$x = chop $y ; # h
4438c4b7 162no warnings 'uninitialized' ;
0453d815 163$x = chop $z ; # h
599cee73
PM
164EXPECT
165Use of uninitialized value at - line 3.
166########
167# sv.c (sv_2pv)
168package fred ;
169sub TIESCALAR { my $x ; bless \$x}
170sub FETCH { return undef }
171sub STORE { return 1 }
172package main ;
173tie $A, 'fred' ;
4438c4b7 174use warnings 'uninitialized' ;
599cee73
PM
175$B = "" ;
176$B .= $A ;
4438c4b7 177no warnings 'uninitialized' ;
0453d815
PM
178$C = "" ;
179$C .= $A ;
599cee73
PM
180EXPECT
181Use of uninitialized value at - line 10.
182########
183# sv.c
4438c4b7 184use warnings 'numeric' ;
599cee73
PM
185sub TIESCALAR{bless[]} ;
186sub FETCH {"def"} ;
187tie $a,"main" ;
0453d815 188my $b = 1 + $a;
4438c4b7 189no warnings 'numeric' ;
0453d815 190my $c = 1 + $a;
599cee73
PM
191EXPECT
192Argument "def" isn't numeric in add at - line 6.
193########
194# sv.c
4438c4b7 195use warnings 'numeric' ;
599cee73 196my $x = 1 + "def" ;
4438c4b7 197no warnings 'numeric' ;
0453d815 198my $z = 1 + "def" ;
599cee73
PM
199EXPECT
200Argument "def" isn't numeric in add at - line 3.
201########
202# sv.c
4438c4b7 203use warnings 'numeric' ;
599cee73
PM
204my $a = "def" ;
205my $x = 1 + $a ;
4438c4b7 206no warnings 'numeric' ;
0453d815 207my $y = 1 + $a ;
599cee73
PM
208EXPECT
209Argument "def" isn't numeric in add at - line 4.
210########
211# sv.c
4438c4b7 212use warnings 'numeric' ; use integer ;
599cee73
PM
213my $a = "def" ;
214my $x = 1 + $a ;
4438c4b7 215no warnings 'numeric' ;
0453d815 216my $z = 1 + $a ;
599cee73
PM
217EXPECT
218Argument "def" isn't numeric in i_add at - line 4.
219########
220# sv.c
4438c4b7 221use warnings 'numeric' ;
599cee73 222my $x = 1 & "def" ;
4438c4b7 223no warnings 'numeric' ;
0453d815 224my $z = 1 & "def" ;
599cee73
PM
225EXPECT
226Argument "def" isn't numeric in bit_and at - line 3.
227########
228# sv.c
4438c4b7 229use warnings 'redefine' ;
599cee73
PM
230sub fred {}
231sub joe {}
232*fred = \&joe ;
4438c4b7 233no warnings 'redefine' ;
0453d815
PM
234sub jim {}
235*jim = \&joe ;
599cee73
PM
236EXPECT
237Subroutine fred redefined at - line 5.
238########
239# sv.c
4438c4b7 240use warnings 'printf' ;
3eeba6fb 241open F, ">".($^O eq 'VMS'? 'NL:' : '/dev/null') ;
cf2093f6
JH
242printf F "%z\n" ;
243my $a = sprintf "%z" ;
599cee73
PM
244printf F "%" ;
245$a = sprintf "%" ;
246printf F "%\x02" ;
247$a = sprintf "%\x02" ;
4438c4b7 248no warnings 'printf' ;
cf2093f6
JH
249printf F "%z\n" ;
250$a = sprintf "%z" ;
0453d815
PM
251printf F "%" ;
252$a = sprintf "%" ;
253printf F "%\x02" ;
254$a = sprintf "%\x02" ;
599cee73 255EXPECT
cf2093f6 256Invalid conversion in sprintf: "%z" at - line 5.
599cee73
PM
257Invalid conversion in sprintf: end of string at - line 7.
258Invalid conversion in sprintf: "%\002" at - line 9.
cf2093f6 259Invalid conversion in printf: "%z" at - line 4.
599cee73
PM
260Invalid conversion in printf: end of string at - line 6.
261Invalid conversion in printf: "%\002" at - line 8.
262########
263# sv.c
4438c4b7 264use warnings 'unsafe' ;
599cee73 265*a = undef ;
4438c4b7 266no warnings 'unsafe' ;
0453d815 267*b = undef ;
599cee73
PM
268EXPECT
269Undefined value assigned to typeglob at - line 3.
0453d815
PM
270########
271# sv.c
272use utf8 ;
273$^W =0 ;
274{
4438c4b7 275 use warnings 'utf8' ;
0453d815 276 my $a = rindex "a\xff bc ", "bc" ;
4438c4b7 277 no warnings 'utf8' ;
0453d815
PM
278 $a = rindex "a\xff bc ", "bc" ;
279}
280my $a = rindex "a\xff bc ", "bc" ;
281EXPECT
282\xff will produce malformed UTF-8 character; use \x{ff} for that at - line 6.
283Malformed UTF-8 character at - line 6.
284Malformed UTF-8 character at - line 10.
6bc102ca
GS
285########
286# sv.c
287use warnings 'misc';
288use Config;
289BEGIN {
290 unless ($Config{ccflags} =~ /Y2KWARN/) {
291 print "SKIPPED\n# perl not built with -DPERL_Y2KWARN";
292 exit 0;
293 }
294 $|=1;
295}
296my $x;
297my $yy = 78;
298$x = printf "19%02d\n", $yy;
299$x = sprintf "#19%02d\n", $yy;
300$x = printf " 19%02d\n", 78;
301$x = sprintf "19%02d\n", 78;
302$x = printf "319%02d\n", $yy;
303$x = sprintf "319%02d\n", $yy;
304no warnings 'misc';
305$x = printf "19%02d\n", $yy;
306$x = sprintf "19%02d\n", $yy;
307$x = printf "19%02d\n", 78;
308$x = sprintf "19%02d\n", 78;
309EXPECT
310Possible Y2K bug: %d format string following '19' at - line 16.
311Possible Y2K bug: %d format string following '19' at - line 13.
3121978
313Possible Y2K bug: %d format string following '19' at - line 14.
314Possible Y2K bug: %d format string following '19' at - line 15.
315 1978
31631978
3171978
3181978