This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate mainline
[perl5.git] / t / pragma / warn / toke
CommitLineData
599cee73
PM
1toke.c AOK
2
3 we seem to have lost a few ambiguous warnings!!
4
5
599cee73
PM
6 $a = <<;
7 Use of comma-less variable list is deprecated
8 (called 3 times via depcom)
9
10 \1 better written as $1
4438c4b7 11 use warnings 'syntax' ;
599cee73
PM
12 s/(abc)/\1/;
13
14 warn(warn_nosemi)
15 Semicolon seems to be missing
16 $a = 1
17 &time ;
18
19
20 Reversed %c= operator
21 my $a =+ 2 ;
22 $a =- 2 ;
23 $a =* 2 ;
24 $a =% 2 ;
25 $a =& 2 ;
26 $a =. 2 ;
27 $a =^ 2 ;
28 $a =| 2 ;
29 $a =< 2 ;
30 $a =/ 2 ;
31
32 Multidimensional syntax %.*s not supported
33 my $a = $a[1,2] ;
34
35 You need to quote \"%s\""
36 sub fred {} ; $SIG{TERM} = fred;
37
38 Scalar value %.*s better written as $%.*s"
39 @a[3] = 2;
40 @a{3} = 2;
41
42 Can't use \\%c to mean $%c in expression
43 $_ = "ab" ; s/(ab)/\1/e;
44
45 Unquoted string "abc" may clash with future reserved word at - line 3.
46 warn(warn_reserved
47 $a = abc;
48
073ca4f1 49 chmod() mode argument is missing initial 0
599cee73
PM
50 chmod 3;
51
52 Possible attempt to separate words with commas
53 @a = qw(a, b, c) ;
54
55 Possible attempt to put comments in qw() list
56 @a = qw(a b # c) ;
57
58 umask: argument is missing initial 0
59 umask 3;
60
61 %s (...) interpreted as function
62 print ("")
63 printf ("")
64 sort ("")
65
66 Ambiguous use of %c{%s%s} resolved to %c%s%s
67 $a = ${time[2]}
68 $a = ${time{2}}
69
70
71 Ambiguous use of %c{%s} resolved to %c%s
72 $a = ${time}
73 sub fred {} $a = ${fred}
74
75 Misplaced _ in number
76 $a = 1_2;
77 $a = 1_2345_6;
78
79 Bareword \"%s\" refers to nonexistent package
80 $a = FRED:: ;
81
82 Ambiguous call resolved as CORE::%s(), qualify as such or use &
83 sub time {}
84 my $a = time()
85
767a6a26
PM
86 Unrecognized escape \\%c passed through
87 $a = "\m" ;
88
89 %s number > %s non-portable
90 my $a = 0b011111111111111111111111111111110 ;
91 $a = 0b011111111111111111111111111111111 ;
92 $a = 0b111111111111111111111111111111111 ;
93 $a = 0x0fffffffe ;
94 $a = 0x0ffffffff ;
95 $a = 0x1ffffffff ;
96 $a = 0037777777776 ;
97 $a = 0037777777777 ;
98 $a = 0047777777777 ;
99
100 Integer overflow in binary number
101 my $a = 0b011111111111111111111111111111110 ;
102 $a = 0b011111111111111111111111111111111 ;
103 $a = 0b111111111111111111111111111111111 ;
104 $a = 0x0fffffffe ;
105 $a = 0x0ffffffff ;
106 $a = 0x1ffffffff ;
107 $a = 0037777777776 ;
108 $a = 0037777777777 ;
109 $a = 0047777777777 ;
599cee73 110
0453d815
PM
111 Mandatory Warnings
112 ------------------
113 Use of "%s" without parentheses is ambiguous [check_uni]
114 rand + 4
115
116 Ambiguous use of -%s resolved as -&%s() [yylex]
117 sub fred {} ; - fred ;
118
119 Precedence problem: open %.*s should be open(%.*s) [yylex]
120 open FOO || die;
121
122 Operator or semicolon missing before %c%s [yylex]
123 Ambiguous use of %c resolved as operator %c
124 *foo *foo
125
599cee73
PM
126__END__
127# toke.c
a4f5cc89 128use warnings 'deprecated' ;
599cee73
PM
129format STDOUT =
130@<<< @||| @>>> @>>>
131$a $b "abc" 'def'
132.
4438c4b7 133no warnings 'deprecated' ;
0453d815
PM
134format STDOUT =
135@<<< @||| @>>> @>>>
136$a $b "abc" 'def'
137.
599cee73
PM
138EXPECT
139Use of comma-less variable list is deprecated at - line 5.
140Use of comma-less variable list is deprecated at - line 5.
141Use of comma-less variable list is deprecated at - line 5.
599cee73
PM
142########
143# toke.c
4438c4b7 144use warnings 'deprecated' ;
599cee73
PM
145$a = <<;
146
4438c4b7 147no warnings 'deprecated' ;
0453d815
PM
148$a = <<;
149
599cee73
PM
150EXPECT
151Use of bare << to mean <<"" is deprecated at - line 3.
152########
153# toke.c
4438c4b7 154use warnings 'syntax' ;
599cee73 155s/(abc)/\1/;
4438c4b7 156no warnings 'syntax' ;
0453d815 157s/(abc)/\1/;
599cee73
PM
158EXPECT
159\1 better written as $1 at - line 3.
160########
161# toke.c
4438c4b7 162use warnings 'semicolon' ;
599cee73
PM
163$a = 1
164&time ;
4438c4b7 165no warnings 'semicolon' ;
0453d815
PM
166$a = 1
167&time ;
599cee73
PM
168EXPECT
169Semicolon seems to be missing at - line 3.
170########
171# toke.c
e4050d25
GS
172BEGIN {
173 # Scalars leaked: due to syntax errors
174 $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
175}
4438c4b7 176use warnings 'syntax' ;
599cee73
PM
177my $a =+ 2 ;
178$a =- 2 ;
179$a =* 2 ;
180$a =% 2 ;
181$a =& 2 ;
182$a =. 2 ;
183$a =^ 2 ;
184$a =| 2 ;
185$a =< 2 ;
186$a =/ 2 ;
187EXPECT
e4050d25
GS
188Reversed += operator at - line 7.
189Reversed -= operator at - line 8.
190Reversed *= operator at - line 9.
191Reversed %= operator at - line 10.
192Reversed &= operator at - line 11.
193Reversed .= operator at - line 12.
e4050d25 194Reversed ^= operator at - line 13.
e4050d25 195Reversed |= operator at - line 14.
e4050d25 196Reversed <= operator at - line 15.
24944567
GS
197syntax error at - line 12, near "=."
198syntax error at - line 13, near "=^"
199syntax error at - line 14, near "=|"
e4050d25 200Unterminated <> operator at - line 15.
599cee73
PM
201########
202# toke.c
0453d815
PM
203BEGIN {
204 # Scalars leaked: due to syntax errors
205 $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
206}
4438c4b7 207no warnings 'syntax' ;
0453d815
PM
208my $a =+ 2 ;
209$a =- 2 ;
210$a =* 2 ;
211$a =% 2 ;
212$a =& 2 ;
213$a =. 2 ;
214$a =^ 2 ;
215$a =| 2 ;
216$a =< 2 ;
217$a =/ 2 ;
218EXPECT
219syntax error at - line 12, near "=."
220syntax error at - line 13, near "=^"
221syntax error at - line 14, near "=|"
222Unterminated <> operator at - line 15.
223########
224# toke.c
4438c4b7 225use warnings 'syntax' ;
599cee73 226my $a = $a[1,2] ;
4438c4b7 227no warnings 'syntax' ;
0453d815 228my $a = $a[1,2] ;
599cee73
PM
229EXPECT
230Multidimensional syntax $a[1,2] not supported at - line 3.
231########
232# toke.c
4438c4b7 233use warnings 'syntax' ;
599cee73 234sub fred {} ; $SIG{TERM} = fred;
4438c4b7 235no warnings 'syntax' ;
0453d815 236$SIG{TERM} = fred;
599cee73
PM
237EXPECT
238You need to quote "fred" at - line 3.
239########
240# toke.c
4438c4b7 241use warnings 'syntax' ;
599cee73
PM
242@a[3] = 2;
243@a{3} = 2;
4438c4b7 244no warnings 'syntax' ;
0453d815
PM
245@a[3] = 2;
246@a{3} = 2;
599cee73
PM
247EXPECT
248Scalar value @a[3] better written as $a[3] at - line 3.
249Scalar value @a{3} better written as $a{3} at - line 4.
250########
251# toke.c
4438c4b7 252use warnings 'syntax' ;
599cee73
PM
253$_ = "ab" ;
254s/(ab)/\1/e;
4438c4b7 255no warnings 'syntax' ;
0453d815
PM
256$_ = "ab" ;
257s/(ab)/\1/e;
599cee73
PM
258EXPECT
259Can't use \1 to mean $1 in expression at - line 4.
260########
261# toke.c
4438c4b7 262use warnings 'reserved' ;
599cee73 263$a = abc;
1c3923b3
GS
264$a = { def
265
266=> 1 };
4438c4b7 267no warnings 'reserved' ;
0453d815 268$a = abc;
599cee73
PM
269EXPECT
270Unquoted string "abc" may clash with future reserved word at - line 3.
271########
272# toke.c
e476b1b5 273use warnings 'chmod' ;
599cee73 274chmod 3;
e476b1b5 275no warnings 'chmod' ;
0453d815 276chmod 3;
599cee73 277EXPECT
073ca4f1 278chmod() mode argument is missing initial 0 at - line 3.
599cee73
PM
279########
280# toke.c
e476b1b5 281use warnings 'qw' ;
599cee73 282@a = qw(a, b, c) ;
e476b1b5 283no warnings 'qw' ;
0453d815 284@a = qw(a, b, c) ;
599cee73
PM
285EXPECT
286Possible attempt to separate words with commas at - line 3.
287########
288# toke.c
e476b1b5 289use warnings 'qw' ;
599cee73 290@a = qw(a b #) ;
e476b1b5 291no warnings 'qw' ;
0453d815 292@a = qw(a b #) ;
599cee73
PM
293EXPECT
294Possible attempt to put comments in qw() list at - line 3.
295########
296# toke.c
e476b1b5 297use warnings 'umask' ;
599cee73 298umask 3;
e476b1b5 299no warnings 'umask' ;
0453d815 300umask 3;
599cee73 301EXPECT
4438c4b7 302umask: argument is missing initial 0 at - line 3.
599cee73
PM
303########
304# toke.c
4438c4b7 305use warnings 'syntax' ;
599cee73
PM
306print ("")
307EXPECT
308print (...) interpreted as function at - line 3.
309########
310# toke.c
4438c4b7 311no warnings 'syntax' ;
0453d815
PM
312print ("")
313EXPECT
314
315########
316# toke.c
4438c4b7 317use warnings 'syntax' ;
599cee73
PM
318printf ("")
319EXPECT
320printf (...) interpreted as function at - line 3.
321########
322# toke.c
4438c4b7 323no warnings 'syntax' ;
0453d815
PM
324printf ("")
325EXPECT
326
327########
328# toke.c
4438c4b7 329use warnings 'syntax' ;
599cee73
PM
330sort ("")
331EXPECT
332sort (...) interpreted as function at - line 3.
333########
334# toke.c
4438c4b7 335no warnings 'syntax' ;
0453d815
PM
336sort ("")
337EXPECT
338
339########
340# toke.c
4438c4b7 341use warnings 'ambiguous' ;
599cee73 342$a = ${time[2]};
4438c4b7 343no warnings 'ambiguous' ;
0453d815 344$a = ${time[2]};
599cee73
PM
345EXPECT
346Ambiguous use of ${time[...]} resolved to $time[...] at - line 3.
347########
348# toke.c
4438c4b7 349use warnings 'ambiguous' ;
599cee73
PM
350$a = ${time{2}};
351EXPECT
352Ambiguous use of ${time{...}} resolved to $time{...} at - line 3.
353########
354# toke.c
4438c4b7 355no warnings 'ambiguous' ;
0453d815
PM
356$a = ${time{2}};
357EXPECT
358
359########
360# toke.c
4438c4b7 361use warnings 'ambiguous' ;
599cee73 362$a = ${time} ;
4438c4b7 363no warnings 'ambiguous' ;
0453d815 364$a = ${time} ;
599cee73
PM
365EXPECT
366Ambiguous use of ${time} resolved to $time at - line 3.
367########
368# toke.c
4438c4b7 369use warnings 'ambiguous' ;
599cee73
PM
370sub fred {}
371$a = ${fred} ;
4438c4b7 372no warnings 'ambiguous' ;
0453d815 373$a = ${fred} ;
599cee73
PM
374EXPECT
375Ambiguous use of ${fred} resolved to $fred at - line 4.
376########
377# toke.c
4438c4b7 378use warnings 'syntax' ;
599cee73
PM
379$a = 1_2;
380$a = 1_2345_6;
4438c4b7 381no warnings 'syntax' ;
0453d815
PM
382$a = 1_2;
383$a = 1_2345_6;
599cee73
PM
384EXPECT
385Misplaced _ in number at - line 3.
386Misplaced _ in number at - line 4.
387Misplaced _ in number at - line 4.
388########
389# toke.c
e476b1b5 390use warnings 'bareword' ;
60e6418e 391#line 25 "bar"
599cee73 392$a = FRED:: ;
e476b1b5 393no warnings 'bareword' ;
0453d815
PM
394#line 25 "bar"
395$a = FRED:: ;
599cee73 396EXPECT
60e6418e 397Bareword "FRED::" refers to nonexistent package at bar line 25.
599cee73
PM
398########
399# toke.c
4438c4b7 400use warnings 'ambiguous' ;
599cee73 401sub time {}
0453d815 402my $a = time() ;
4438c4b7 403no warnings 'ambiguous' ;
0453d815 404my $b = time() ;
599cee73
PM
405EXPECT
406Ambiguous call resolved as CORE::time(), qualify as such or use & at - line 4.
407########
408# toke.c
26d16222 409use warnings ;
0453d815 410eval <<'EOE';
df0deb90
GS
411# line 30 "foo"
412warn "yelp";
0453d815 413{
0453d815
PM
414 $_ = " \x{123} " ;
415}
416EOE
417EXPECT
df0deb90 418yelp at foo line 30.
0453d815
PM
419########
420# toke.c
0453d815
PM
421my $a = rand + 4 ;
422EXPECT
423Warning: Use of "rand" without parens is ambiguous at - line 2.
424########
425# toke.c
426$^W = 0 ;
427my $a = rand + 4 ;
428{
4438c4b7 429 no warnings 'ambiguous' ;
0453d815 430 $a = rand + 4 ;
4438c4b7 431 use warnings 'ambiguous' ;
0453d815
PM
432 $a = rand + 4 ;
433}
434$a = rand + 4 ;
435EXPECT
436Warning: Use of "rand" without parens is ambiguous at - line 3.
437Warning: Use of "rand" without parens is ambiguous at - line 8.
438Warning: Use of "rand" without parens is ambiguous at - line 10.
439########
440# toke.c
441sub fred {};
442-fred ;
443EXPECT
444Ambiguous use of -fred resolved as -&fred() at - line 3.
445########
446# toke.c
447$^W = 0 ;
448sub fred {} ;
449-fred ;
450{
4438c4b7 451 no warnings 'ambiguous' ;
0453d815 452 -fred ;
4438c4b7 453 use warnings 'ambiguous' ;
0453d815
PM
454 -fred ;
455}
456-fred ;
457EXPECT
458Ambiguous use of -fred resolved as -&fred() at - line 4.
459Ambiguous use of -fred resolved as -&fred() at - line 9.
460Ambiguous use of -fred resolved as -&fred() at - line 11.
461########
462# toke.c
463open FOO || time;
464EXPECT
465Precedence problem: open FOO should be open(FOO) at - line 2.
466########
467# toke.c
468$^W = 0 ;
469open FOO || time;
470{
e476b1b5 471 no warnings 'precedence' ;
0453d815 472 open FOO || time;
e476b1b5 473 use warnings 'precedence' ;
0453d815
PM
474 open FOO || time;
475}
476open FOO || time;
477EXPECT
478Precedence problem: open FOO should be open(FOO) at - line 3.
479Precedence problem: open FOO should be open(FOO) at - line 8.
480Precedence problem: open FOO should be open(FOO) at - line 10.
481########
482# toke.c
483$^W = 0 ;
484*foo *foo ;
485{
4438c4b7 486 no warnings 'ambiguous' ;
0453d815 487 *foo *foo ;
4438c4b7 488 use warnings 'ambiguous' ;
0453d815
PM
489 *foo *foo ;
490}
491*foo *foo ;
492EXPECT
493Operator or semicolon missing before *foo at - line 3.
494Ambiguous use of * resolved as operator * at - line 3.
495Operator or semicolon missing before *foo at - line 8.
496Ambiguous use of * resolved as operator * at - line 8.
497Operator or semicolon missing before *foo at - line 10.
498Ambiguous use of * resolved as operator * at - line 10.
767a6a26
PM
499########
500# toke.c
e476b1b5 501use warnings 'misc' ;
767a6a26 502my $a = "\m" ;
e476b1b5 503no warnings 'misc' ;
767a6a26
PM
504$a = "\m" ;
505EXPECT
506Unrecognized escape \m passed through at - line 3.
507########
508# toke.c
509use warnings 'portable' ;
510my $a = 0b011111111111111111111111111111110 ;
511 $a = 0b011111111111111111111111111111111 ;
512 $a = 0b111111111111111111111111111111111 ;
513 $a = 0x0fffffffe ;
514 $a = 0x0ffffffff ;
515 $a = 0x1ffffffff ;
516 $a = 0037777777776 ;
517 $a = 0037777777777 ;
518 $a = 0047777777777 ;
519no warnings 'portable' ;
520 $a = 0b011111111111111111111111111111110 ;
521 $a = 0b011111111111111111111111111111111 ;
522 $a = 0b111111111111111111111111111111111 ;
523 $a = 0x0fffffffe ;
524 $a = 0x0ffffffff ;
525 $a = 0x1ffffffff ;
526 $a = 0037777777776 ;
527 $a = 0037777777777 ;
528 $a = 0047777777777 ;
529EXPECT
530Binary number > 0b11111111111111111111111111111111 non-portable at - line 5.
531Hexadecimal number > 0xffffffff non-portable at - line 8.
532Octal number > 037777777777 non-portable at - line 11.
533########
534# toke.c
535use warnings 'overflow' ;
536my $a = 0b011111111111111111111111111111110 ;
537 $a = 0b011111111111111111111111111111111 ;
15041a67 538 $a = 0b10000000000000000000000000000000000000000000000000000000000000000 ;
767a6a26
PM
539 $a = 0x0fffffffe ;
540 $a = 0x0ffffffff ;
15041a67 541 $a = 0x10000000000000000 ;
767a6a26
PM
542 $a = 0037777777776 ;
543 $a = 0037777777777 ;
15041a67 544 $a = 002000000000000000000000;
767a6a26
PM
545no warnings 'overflow' ;
546 $a = 0b011111111111111111111111111111110 ;
547 $a = 0b011111111111111111111111111111111 ;
15041a67 548 $a = 0b10000000000000000000000000000000000000000000000000000000000000000 ;
767a6a26
PM
549 $a = 0x0fffffffe ;
550 $a = 0x0ffffffff ;
15041a67 551 $a = 0x10000000000000000 ;
767a6a26
PM
552 $a = 0037777777776 ;
553 $a = 0037777777777 ;
15041a67 554 $a = 002000000000000000000000;
767a6a26
PM
555EXPECT
556Integer overflow in binary number at - line 5.
557Integer overflow in hexadecimal number at - line 8.
558Integer overflow in octal number at - line 11.
8593bda5
GS
559########
560# toke.c
561use warnings 'ambiguous';
562"@mjd_previously_unused_array";
563no warnings 'ambiguous';
564"@mjd_previously_unused_array";
565EXPECT
566Possible unintended interpolation of @mjd_previously_unused_array in string at - line 3.