This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test that defined warns for package arrays and hashes.
[perl5.git] / t / lib / warnings / pp
CommitLineData
599cee73
PM
1 pp.c TODO
2
3 substr outside of string
e476b1b5 4 $a = "ab" ; $b = substr($a, 4,5) ;
599cee73
PM
5
6 Attempt to use reference as lvalue in substr
7 $a = "ab" ; $b = \$a ; substr($b, 1,1) = $b
8
3b434eb1 9 Use of uninitialized value in scalar dereference [pp_rv2sv()]
599cee73
PM
10 my $a = undef ; my $b = $$a
11
12 Odd number of elements in hash list
13 my $a = { 1,2,3 } ;
14
599cee73
PM
15 Explicit blessing to '' (assuming package main)
16 bless \[], "";
17
3b434eb1
RGS
18 Constant subroutine %s undefined
19 sub foo () { 1 }; undef &foo;
20
21 Constant subroutine (anonymous) undefined
22 $foo = sub () { 3 }; undef &$foo;
0453d815 23
599cee73
PM
24__END__
25# pp.c
4438c4b7 26use warnings 'substr' ;
599cee73 27$a = "ab" ;
e476b1b5 28$b = substr($a, 4,5) ;
4438c4b7 29no warnings 'substr' ;
0453d815 30$a = "ab" ;
e476b1b5 31$b = substr($a, 4,5) ;
599cee73
PM
32EXPECT
33substr outside of string at - line 4.
34########
35# pp.c
4438c4b7 36use warnings 'substr' ;
599cee73
PM
37$a = "ab" ;
38$b = \$a ;
39substr($b, 1,1) = "ab" ;
4438c4b7 40no warnings 'substr' ;
0453d815 41substr($b, 1,1) = "ab" ;
599cee73
PM
42EXPECT
43Attempt to use reference as lvalue in substr at - line 5.
44########
45# pp.c
5cd408a2
EB
46use warnings 'misc' ;
47@a = qw( a b c );
48splice(@a, 4, 0, 'e') ;
49@a = qw( a b c );
50splice(@a, 4, 1) ;
51@a = qw( a b c );
52splice(@a, 4) ;
53no warnings 'misc' ;
54@a = qw( a b c );
55splice(@a, 4, 0, 'e') ;
56@a = qw( a b c );
57splice(@a, 4, 1) ;
58@a = qw( a b c );
59splice(@a, 4) ;
60EXPECT
61splice() offset past end of array at - line 4.
62splice() offset past end of array at - line 6.
63########
64# pp.c
3b434eb1
RGS
65use warnings 'uninitialized';
66$x = undef; $y = $$x;
67no warnings 'uninitialized' ;
68$u = undef; $v = $$u;
69EXPECT
29489e7c 70Use of uninitialized value $x in scalar dereference at - line 3.
599cee73
PM
71########
72# pp.c
e476b1b5 73use warnings 'misc' ;
599cee73 74my $a = { 1,2,3};
e476b1b5 75no warnings 'misc' ;
0453d815 76my $b = { 1,2,3};
599cee73 77EXPECT
b21befc1 78Odd number of elements in anonymous hash at - line 3.
599cee73 79########
599cee73 80# pp.c
e476b1b5 81use warnings 'misc' ;
599cee73 82bless \[], "" ;
e476b1b5 83no warnings 'misc' ;
0453d815 84bless \[], "" ;
599cee73
PM
85EXPECT
86Explicit blessing to '' (assuming package main) at - line 3.
0453d815
PM
87########
88# pp.c
3b434eb1
RGS
89use warnings 'misc';
90sub foo () { 1 }
91undef &foo;
92no warnings 'misc';
93sub bar () { 2 }
94undef &bar;
95EXPECT
96Constant subroutine foo undefined at - line 4.
97########
98# pp.c
714cd18f
BF
99use utf8;
100use open qw( :utf8 :std );
101use warnings 'misc';
102sub ฝᶱ () { 1 }
103undef &ฝᶱ;
104no warnings 'misc';
105sub ƚ () { 2 }
106undef &ƚ;
107EXPECT
108Constant subroutine ฝᶱ undefined at - line 6.
109########
110# pp.c
3b434eb1
RGS
111use warnings 'misc';
112$foo = sub () { 3 };
113undef &$foo;
114no warnings 'misc';
115$bar = sub () { 4 };
116undef &$bar;
117EXPECT
118Constant subroutine (anonymous) undefined at - line 4.
119########
120# pp.c
0453d815
PM
121use utf8 ;
122$_ = "\x80 \xff" ;
123reverse ;
124EXPECT