This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
improvements for high-bit text literals (from Gisle Aas)
[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 ------------------
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' ;
599cee73 115my $x *= 1 ; # d
4438c4b7 116no warnings 'uninitialized' ;
0453d815 117my $y *= 1 ; # d
599cee73 118EXPECT
b89fed5f 119Use of uninitialized value in multiplication (*) at - line 3.
599cee73
PM
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 126EXPECT
b89fed5f 127Use of uninitialized value in addition (+) at - line 3.
599cee73
PM
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 140EXPECT
b89fed5f 141Use of uninitialized value in multiplication (*) at - line 9.
599cee73
PM
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 148EXPECT
b89fed5f 149Use of uninitialized value in addition (+) at - line 3.
599cee73
PM
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 164EXPECT
b89fed5f 165Use of uninitialized value in scalar chop at - line 3.
599cee73
PM
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 180EXPECT
b89fed5f 181Use of uninitialized value in concatenation (.) at - line 10.
599cee73
PM
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 191EXPECT
42d38218 192Argument "def" isn't numeric in addition (+) at - line 6.
599cee73
PM
193########
194# sv.c
4438c4b7 195use warnings 'numeric' ;
599cee73 196my $x = 1 + "def" ;
4438c4b7 197no warnings 'numeric' ;
0453d815 198my $z = 1 + "def" ;
599cee73 199EXPECT
42d38218 200Argument "def" isn't numeric in addition (+) at - line 3.
599cee73
PM
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 208EXPECT
42d38218 209Argument "def" isn't numeric in addition (+) at - line 4.
599cee73
PM
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 217EXPECT
42d38218 218Argument "def" isn't numeric in integer addition (+) at - line 4.
599cee73
PM
219########
220# sv.c
4438c4b7 221use warnings 'numeric' ;
599cee73 222my $x = 1 & "def" ;
4438c4b7 223no warnings 'numeric' ;
0453d815 224my $z = 1 & "def" ;
599cee73 225EXPECT
42d38218 226Argument "def" isn't numeric in bitwise and (&) at - line 3.
599cee73
PM
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
e476b1b5 264use warnings 'misc' ;
599cee73 265*a = undef ;
e476b1b5 266no warnings 'misc' ;
0453d815 267*b = undef ;
599cee73
PM
268EXPECT
269Undefined value assigned to typeglob at - line 3.
0453d815
PM
270########
271# sv.c
e476b1b5 272use warnings 'y2k';
6bc102ca
GS
273use Config;
274BEGIN {
275 unless ($Config{ccflags} =~ /Y2KWARN/) {
276 print "SKIPPED\n# perl not built with -DPERL_Y2KWARN";
277 exit 0;
278 }
279 $|=1;
280}
281my $x;
282my $yy = 78;
283$x = printf "19%02d\n", $yy;
284$x = sprintf "#19%02d\n", $yy;
285$x = printf " 19%02d\n", 78;
286$x = sprintf "19%02d\n", 78;
287$x = printf "319%02d\n", $yy;
288$x = sprintf "319%02d\n", $yy;
e476b1b5 289no warnings 'y2k';
6bc102ca
GS
290$x = printf "19%02d\n", $yy;
291$x = sprintf "19%02d\n", $yy;
292$x = printf "19%02d\n", 78;
293$x = sprintf "19%02d\n", 78;
294EXPECT
295Possible Y2K bug: %d format string following '19' at - line 16.
296Possible Y2K bug: %d format string following '19' at - line 13.
2971978
298Possible Y2K bug: %d format string following '19' at - line 14.
299Possible Y2K bug: %d format string following '19' at - line 15.
300 1978
30131978
3021978
3031978