This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
CodeMagicCD doesn't look like an *I*DE.
[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
4438c4b7 172use warnings 'syntax' ;
599cee73
PM
173my $a =+ 2 ;
174$a =- 2 ;
175$a =* 2 ;
176$a =% 2 ;
177$a =& 2 ;
178$a =. 2 ;
179$a =^ 2 ;
180$a =| 2 ;
181$a =< 2 ;
182$a =/ 2 ;
183EXPECT
7f01dc7a
JH
184Reversed += operator at - line 3.
185Reversed -= operator at - line 4.
186Reversed *= operator at - line 5.
187Reversed %= operator at - line 6.
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.
193syntax error at - line 8, near "=."
194syntax error at - line 9, near "=^"
195syntax error at - line 10, near "=|"
196Unterminated <> operator at - line 11.
599cee73
PM
197########
198# toke.c
4438c4b7 199no warnings 'syntax' ;
0453d815
PM
200my $a =+ 2 ;
201$a =- 2 ;
202$a =* 2 ;
203$a =% 2 ;
204$a =& 2 ;
205$a =. 2 ;
206$a =^ 2 ;
207$a =| 2 ;
208$a =< 2 ;
209$a =/ 2 ;
210EXPECT
7f01dc7a
JH
211syntax error at - line 8, near "=."
212syntax error at - line 9, near "=^"
213syntax error at - line 10, near "=|"
214Unterminated <> operator at - line 11.
0453d815
PM
215########
216# toke.c
4438c4b7 217use warnings 'syntax' ;
599cee73 218my $a = $a[1,2] ;
4438c4b7 219no warnings 'syntax' ;
0453d815 220my $a = $a[1,2] ;
599cee73
PM
221EXPECT
222Multidimensional syntax $a[1,2] not supported at - line 3.
223########
224# toke.c
4438c4b7 225use warnings 'syntax' ;
599cee73 226sub fred {} ; $SIG{TERM} = fred;
4438c4b7 227no warnings 'syntax' ;
0453d815 228$SIG{TERM} = fred;
599cee73
PM
229EXPECT
230You need to quote "fred" at - line 3.
231########
232# toke.c
4438c4b7 233use warnings 'syntax' ;
599cee73
PM
234@a[3] = 2;
235@a{3} = 2;
4438c4b7 236no warnings 'syntax' ;
0453d815
PM
237@a[3] = 2;
238@a{3} = 2;
599cee73
PM
239EXPECT
240Scalar value @a[3] better written as $a[3] at - line 3.
241Scalar value @a{3} better written as $a{3} at - line 4.
242########
243# toke.c
4438c4b7 244use warnings 'syntax' ;
599cee73
PM
245$_ = "ab" ;
246s/(ab)/\1/e;
4438c4b7 247no warnings 'syntax' ;
0453d815
PM
248$_ = "ab" ;
249s/(ab)/\1/e;
599cee73
PM
250EXPECT
251Can't use \1 to mean $1 in expression at - line 4.
252########
253# toke.c
4438c4b7 254use warnings 'reserved' ;
599cee73 255$a = abc;
1c3923b3
GS
256$a = { def
257
258=> 1 };
4438c4b7 259no warnings 'reserved' ;
0453d815 260$a = abc;
599cee73
PM
261EXPECT
262Unquoted string "abc" may clash with future reserved word at - line 3.
263########
264# toke.c
e476b1b5 265use warnings 'chmod' ;
599cee73 266chmod 3;
e476b1b5 267no warnings 'chmod' ;
0453d815 268chmod 3;
599cee73 269EXPECT
073ca4f1 270chmod() mode argument is missing initial 0 at - line 3.
599cee73
PM
271########
272# toke.c
e476b1b5 273use warnings 'qw' ;
599cee73 274@a = qw(a, b, c) ;
e476b1b5 275no warnings 'qw' ;
0453d815 276@a = qw(a, b, c) ;
599cee73
PM
277EXPECT
278Possible attempt to separate words with commas at - line 3.
279########
280# toke.c
e476b1b5 281use warnings 'qw' ;
599cee73 282@a = qw(a b #) ;
e476b1b5 283no warnings 'qw' ;
0453d815 284@a = qw(a b #) ;
599cee73
PM
285EXPECT
286Possible attempt to put comments in qw() list at - line 3.
287########
288# toke.c
e476b1b5 289use warnings 'umask' ;
599cee73 290umask 3;
e476b1b5 291no warnings 'umask' ;
0453d815 292umask 3;
599cee73 293EXPECT
4438c4b7 294umask: argument is missing initial 0 at - line 3.
599cee73
PM
295########
296# toke.c
4438c4b7 297use warnings 'syntax' ;
599cee73
PM
298print ("")
299EXPECT
300print (...) interpreted as function at - line 3.
301########
302# toke.c
4438c4b7 303no warnings 'syntax' ;
0453d815
PM
304print ("")
305EXPECT
306
307########
308# toke.c
4438c4b7 309use warnings 'syntax' ;
599cee73
PM
310printf ("")
311EXPECT
312printf (...) interpreted as function at - line 3.
313########
314# toke.c
4438c4b7 315no warnings 'syntax' ;
0453d815
PM
316printf ("")
317EXPECT
318
319########
320# toke.c
4438c4b7 321use warnings 'syntax' ;
599cee73
PM
322sort ("")
323EXPECT
324sort (...) interpreted as function at - line 3.
325########
326# toke.c
4438c4b7 327no warnings 'syntax' ;
0453d815
PM
328sort ("")
329EXPECT
330
331########
332# toke.c
4438c4b7 333use warnings 'ambiguous' ;
599cee73 334$a = ${time[2]};
4438c4b7 335no warnings 'ambiguous' ;
0453d815 336$a = ${time[2]};
599cee73
PM
337EXPECT
338Ambiguous use of ${time[...]} resolved to $time[...] at - line 3.
339########
340# toke.c
4438c4b7 341use warnings 'ambiguous' ;
599cee73
PM
342$a = ${time{2}};
343EXPECT
344Ambiguous use of ${time{...}} resolved to $time{...} at - line 3.
345########
346# toke.c
4438c4b7 347no warnings 'ambiguous' ;
0453d815
PM
348$a = ${time{2}};
349EXPECT
350
351########
352# toke.c
4438c4b7 353use warnings 'ambiguous' ;
599cee73 354$a = ${time} ;
4438c4b7 355no warnings 'ambiguous' ;
0453d815 356$a = ${time} ;
599cee73
PM
357EXPECT
358Ambiguous use of ${time} resolved to $time at - line 3.
359########
360# toke.c
4438c4b7 361use warnings 'ambiguous' ;
599cee73
PM
362sub fred {}
363$a = ${fred} ;
4438c4b7 364no warnings 'ambiguous' ;
0453d815 365$a = ${fred} ;
599cee73
PM
366EXPECT
367Ambiguous use of ${fred} resolved to $fred at - line 4.
368########
369# toke.c
4438c4b7 370use warnings 'syntax' ;
928753ea
JH
371$a = _123; print "$a\n"; # not a number, a string
372$a = 1_23; print "$a\n";
373$a = 1__3; print "$a\n"; # misplaced [ 5]
374$a = 123_; print "$a\n"; # misplaced [ 6]
375$a = 123._456; print "$a\n"; # misplaced [ 7]
376$a = 123.4_56; print "$a\n";
377$a = 123.4__6; print "$a\n"; # misplaced [ 9]
378$a = 123.456_; print "$a\n"; # misplaced [10]
379$a = 0b_101; print "$a\n"; # misplaced [11]
380$a = 0b1_01; print "$a\n";
381$a = 0b1__1; print "$a\n"; # misplaced [13]
382$a = 0b101_; print "$a\n"; # misplaced [14]
383$a = 0_123; print "$a\n"; # misplaced [15]
384$a = 01_23; print "$a\n";
385$a = 01__3; print "$a\n"; # misplaced [17]
386$a = 0123_; print "$a\n"; # misplaced [18]
387$a = 0x_123; print "$a\n"; # misplaced [19]
388$a = 0x1_23; print "$a\n";
389$a = 0x1__3; print "$a\n"; # misplaced [21]
390$a = 0x123_; print "$a\n"; # misplaced [22]
4438c4b7 391no warnings 'syntax' ;
599cee73 392EXPECT
928753ea
JH
393Misplaced _ in number at - line 5.
394Misplaced _ in number at - line 6.
395Misplaced _ in number at - line 7.
396Misplaced _ in number at - line 9.
397Misplaced _ in number at - line 10.
398Misplaced _ in number at - line 11.
399Misplaced _ in number at - line 13.
400Misplaced _ in number at - line 14.
401Misplaced _ in number at - line 15.
402Misplaced _ in number at - line 17.
403Misplaced _ in number at - line 18.
404Misplaced _ in number at - line 19.
405Misplaced _ in number at - line 21.
406Misplaced _ in number at - line 22.
407_123
408123
40913
410123
411123.456
412123.456
413123.46
414123.456
4155
4165
4173
4185
41983
42083
42111
42283
423291
424291
42519
426291
599cee73
PM
427########
428# toke.c
e476b1b5 429use warnings 'bareword' ;
60e6418e 430#line 25 "bar"
599cee73 431$a = FRED:: ;
e476b1b5 432no warnings 'bareword' ;
0453d815
PM
433#line 25 "bar"
434$a = FRED:: ;
599cee73 435EXPECT
60e6418e 436Bareword "FRED::" refers to nonexistent package at bar line 25.
599cee73
PM
437########
438# toke.c
4438c4b7 439use warnings 'ambiguous' ;
599cee73 440sub time {}
0453d815 441my $a = time() ;
4438c4b7 442no warnings 'ambiguous' ;
0453d815 443my $b = time() ;
599cee73
PM
444EXPECT
445Ambiguous call resolved as CORE::time(), qualify as such or use & at - line 4.
446########
447# toke.c
26d16222 448use warnings ;
0453d815 449eval <<'EOE';
df0deb90
GS
450# line 30 "foo"
451warn "yelp";
0453d815 452{
0453d815
PM
453 $_ = " \x{123} " ;
454}
455EOE
456EXPECT
df0deb90 457yelp at foo line 30.
0453d815
PM
458########
459# toke.c
0453d815
PM
460my $a = rand + 4 ;
461EXPECT
462Warning: Use of "rand" without parens is ambiguous at - line 2.
463########
464# toke.c
465$^W = 0 ;
466my $a = rand + 4 ;
467{
4438c4b7 468 no warnings 'ambiguous' ;
0453d815 469 $a = rand + 4 ;
4438c4b7 470 use warnings 'ambiguous' ;
0453d815
PM
471 $a = rand + 4 ;
472}
473$a = rand + 4 ;
474EXPECT
475Warning: Use of "rand" without parens is ambiguous at - line 3.
476Warning: Use of "rand" without parens is ambiguous at - line 8.
477Warning: Use of "rand" without parens is ambiguous at - line 10.
478########
479# toke.c
480sub fred {};
481-fred ;
482EXPECT
483Ambiguous use of -fred resolved as -&fred() at - line 3.
484########
485# toke.c
486$^W = 0 ;
487sub fred {} ;
488-fred ;
489{
4438c4b7 490 no warnings 'ambiguous' ;
0453d815 491 -fred ;
4438c4b7 492 use warnings 'ambiguous' ;
0453d815
PM
493 -fred ;
494}
495-fred ;
496EXPECT
497Ambiguous use of -fred resolved as -&fred() at - line 4.
498Ambiguous use of -fred resolved as -&fred() at - line 9.
499Ambiguous use of -fred resolved as -&fred() at - line 11.
500########
501# toke.c
502open FOO || time;
503EXPECT
504Precedence problem: open FOO should be open(FOO) at - line 2.
505########
506# toke.c
507$^W = 0 ;
508open FOO || time;
509{
e476b1b5 510 no warnings 'precedence' ;
0453d815 511 open FOO || time;
e476b1b5 512 use warnings 'precedence' ;
0453d815
PM
513 open FOO || time;
514}
515open FOO || time;
516EXPECT
517Precedence problem: open FOO should be open(FOO) at - line 3.
518Precedence problem: open FOO should be open(FOO) at - line 8.
519Precedence problem: open FOO should be open(FOO) at - line 10.
520########
521# toke.c
522$^W = 0 ;
523*foo *foo ;
524{
4438c4b7 525 no warnings 'ambiguous' ;
0453d815 526 *foo *foo ;
4438c4b7 527 use warnings 'ambiguous' ;
0453d815
PM
528 *foo *foo ;
529}
530*foo *foo ;
531EXPECT
532Operator or semicolon missing before *foo at - line 3.
533Ambiguous use of * resolved as operator * at - line 3.
534Operator or semicolon missing before *foo at - line 8.
535Ambiguous use of * resolved as operator * at - line 8.
536Operator or semicolon missing before *foo at - line 10.
537Ambiguous use of * resolved as operator * at - line 10.
767a6a26
PM
538########
539# toke.c
e476b1b5 540use warnings 'misc' ;
767a6a26 541my $a = "\m" ;
e476b1b5 542no warnings 'misc' ;
767a6a26
PM
543$a = "\m" ;
544EXPECT
545Unrecognized escape \m passed through at - line 3.
546########
547# toke.c
548use warnings 'portable' ;
549my $a = 0b011111111111111111111111111111110 ;
550 $a = 0b011111111111111111111111111111111 ;
551 $a = 0b111111111111111111111111111111111 ;
552 $a = 0x0fffffffe ;
553 $a = 0x0ffffffff ;
554 $a = 0x1ffffffff ;
555 $a = 0037777777776 ;
556 $a = 0037777777777 ;
557 $a = 0047777777777 ;
558no warnings 'portable' ;
559 $a = 0b011111111111111111111111111111110 ;
560 $a = 0b011111111111111111111111111111111 ;
561 $a = 0b111111111111111111111111111111111 ;
562 $a = 0x0fffffffe ;
563 $a = 0x0ffffffff ;
564 $a = 0x1ffffffff ;
565 $a = 0037777777776 ;
566 $a = 0037777777777 ;
567 $a = 0047777777777 ;
568EXPECT
569Binary number > 0b11111111111111111111111111111111 non-portable at - line 5.
570Hexadecimal number > 0xffffffff non-portable at - line 8.
571Octal number > 037777777777 non-portable at - line 11.
572########
573# toke.c
574use warnings 'overflow' ;
575my $a = 0b011111111111111111111111111111110 ;
576 $a = 0b011111111111111111111111111111111 ;
15041a67 577 $a = 0b10000000000000000000000000000000000000000000000000000000000000000 ;
767a6a26
PM
578 $a = 0x0fffffffe ;
579 $a = 0x0ffffffff ;
15041a67 580 $a = 0x10000000000000000 ;
767a6a26
PM
581 $a = 0037777777776 ;
582 $a = 0037777777777 ;
15041a67 583 $a = 002000000000000000000000;
767a6a26
PM
584no warnings 'overflow' ;
585 $a = 0b011111111111111111111111111111110 ;
586 $a = 0b011111111111111111111111111111111 ;
15041a67 587 $a = 0b10000000000000000000000000000000000000000000000000000000000000000 ;
767a6a26
PM
588 $a = 0x0fffffffe ;
589 $a = 0x0ffffffff ;
15041a67 590 $a = 0x10000000000000000 ;
767a6a26
PM
591 $a = 0037777777776 ;
592 $a = 0037777777777 ;
15041a67 593 $a = 002000000000000000000000;
767a6a26
PM
594EXPECT
595Integer overflow in binary number at - line 5.
596Integer overflow in hexadecimal number at - line 8.
597Integer overflow in octal number at - line 11.
8593bda5
GS
598########
599# toke.c
600use warnings 'ambiguous';
601"@mjd_previously_unused_array";
602no warnings 'ambiguous';
603"@mjd_previously_unused_array";
604EXPECT
605Possible unintended interpolation of @mjd_previously_unused_array in string at - line 3.