This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
toke.c: 'Scalar value %s better written as $%s' cleanup.
[perl5.git] / t / lib / warnings / 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
599cee73
PM
49 Possible attempt to separate words with commas
50 @a = qw(a, b, c) ;
51
52 Possible attempt to put comments in qw() list
53 @a = qw(a b # c) ;
54
599cee73
PM
55 %s (...) interpreted as function
56 print ("")
57 printf ("")
58 sort ("")
59
60 Ambiguous use of %c{%s%s} resolved to %c%s%s
61 $a = ${time[2]}
62 $a = ${time{2}}
63
64
65 Ambiguous use of %c{%s} resolved to %c%s
66 $a = ${time}
67 sub fred {} $a = ${fred}
68
69 Misplaced _ in number
70 $a = 1_2;
71 $a = 1_2345_6;
72
73 Bareword \"%s\" refers to nonexistent package
74 $a = FRED:: ;
75
76 Ambiguous call resolved as CORE::%s(), qualify as such or use &
77 sub time {}
78 my $a = time()
79
767a6a26
PM
80 Unrecognized escape \\%c passed through
81 $a = "\m" ;
82
820438b1 83 Useless use of \\E.
52ed07f6
BF
84 $a = "abcd\E" ;
85
767a6a26
PM
86 %s number > %s non-portable
87 my $a = 0b011111111111111111111111111111110 ;
88 $a = 0b011111111111111111111111111111111 ;
89 $a = 0b111111111111111111111111111111111 ;
90 $a = 0x0fffffffe ;
91 $a = 0x0ffffffff ;
92 $a = 0x1ffffffff ;
93 $a = 0037777777776 ;
94 $a = 0037777777777 ;
95 $a = 0047777777777 ;
96
97 Integer overflow in binary number
98 my $a = 0b011111111111111111111111111111110 ;
99 $a = 0b011111111111111111111111111111111 ;
100 $a = 0b111111111111111111111111111111111 ;
101 $a = 0x0fffffffe ;
102 $a = 0x0ffffffff ;
103 $a = 0x1ffffffff ;
104 $a = 0037777777776 ;
105 $a = 0037777777777 ;
106 $a = 0047777777777 ;
ac206dc8
RGS
107
108 dump() better written as CORE::dump()
4ac733c9
MJD
109
110 Use of /c modifier is meaningless without /g
111
64e578a2
MJD
112 Use of /c modifier is meaningless in s///
113
0453d815
PM
114 Mandatory Warnings
115 ------------------
116 Use of "%s" without parentheses is ambiguous [check_uni]
117 rand + 4
118
119 Ambiguous use of -%s resolved as -&%s() [yylex]
120 sub fred {} ; - fred ;
121
122 Precedence problem: open %.*s should be open(%.*s) [yylex]
123 open FOO || die;
124
125 Operator or semicolon missing before %c%s [yylex]
126 Ambiguous use of %c resolved as operator %c
127 *foo *foo
128
599cee73
PM
129__END__
130# toke.c
599cee73
PM
131format STDOUT =
132@<<< @||| @>>> @>>>
133$a $b "abc" 'def'
134.
4438c4b7 135no warnings 'deprecated' ;
0453d815
PM
136format STDOUT =
137@<<< @||| @>>> @>>>
138$a $b "abc" 'def'
139.
599cee73 140EXPECT
d1d15184
NC
141Use of comma-less variable list is deprecated at - line 4.
142Use of comma-less variable list is deprecated at - line 4.
143Use of comma-less variable list is deprecated at - line 4.
599cee73
PM
144########
145# toke.c
e6897b1a 146$a =~ m/$foo/sand $bar;
aa78b661 147$a =~ s/$foo/fool/sand $bar;
599cee73
PM
148$a = <<;
149
4438c4b7 150no warnings 'deprecated' ;
e6897b1a 151$a =~ m/$foo/sand $bar;
aa78b661 152$a =~ s/$foo/fool/sand $bar;
0453d815
PM
153$a = <<;
154
599cee73 155EXPECT
e6897b1a 156Having no space between pattern and following word is deprecated at - line 2.
aa78b661
KW
157Having no space between pattern and following word is deprecated at - line 3.
158Use of bare << to mean <<"" is deprecated at - line 4.
599cee73
PM
159########
160# toke.c
4438c4b7 161use warnings 'syntax' ;
599cee73 162s/(abc)/\1/;
4438c4b7 163no warnings 'syntax' ;
0453d815 164s/(abc)/\1/;
599cee73
PM
165EXPECT
166\1 better written as $1 at - line 3.
167########
168# toke.c
4438c4b7 169use warnings 'semicolon' ;
599cee73
PM
170$a = 1
171&time ;
4438c4b7 172no warnings 'semicolon' ;
0453d815
PM
173$a = 1
174&time ;
599cee73
PM
175EXPECT
176Semicolon seems to be missing at - line 3.
177########
178# toke.c
4438c4b7 179use warnings 'syntax' ;
599cee73
PM
180my $a =+ 2 ;
181$a =- 2 ;
182$a =* 2 ;
183$a =% 2 ;
184$a =& 2 ;
185$a =. 2 ;
186$a =^ 2 ;
187$a =| 2 ;
188$a =< 2 ;
189$a =/ 2 ;
190EXPECT
7f01dc7a
JH
191Reversed += operator at - line 3.
192Reversed -= operator at - line 4.
193Reversed *= operator at - line 5.
194Reversed %= operator at - line 6.
195Reversed &= operator at - line 7.
196Reversed .= operator at - line 8.
197Reversed ^= operator at - line 9.
198Reversed |= operator at - line 10.
199Reversed <= operator at - line 11.
200syntax error at - line 8, near "=."
201syntax error at - line 9, near "=^"
202syntax error at - line 10, near "=|"
203Unterminated <> operator at - line 11.
599cee73
PM
204########
205# toke.c
4438c4b7 206no warnings 'syntax' ;
0453d815
PM
207my $a =+ 2 ;
208$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 ;
217EXPECT
7f01dc7a
JH
218syntax error at - line 8, near "=."
219syntax error at - line 9, near "=^"
220syntax error at - line 10, near "=|"
221Unterminated <> operator at - line 11.
0453d815
PM
222########
223# toke.c
4438c4b7 224use warnings 'syntax' ;
599cee73 225my $a = $a[1,2] ;
4438c4b7 226no warnings 'syntax' ;
0453d815 227my $a = $a[1,2] ;
599cee73
PM
228EXPECT
229Multidimensional syntax $a[1,2] not supported at - line 3.
230########
231# toke.c
4438c4b7 232use warnings 'syntax' ;
599cee73 233sub fred {} ; $SIG{TERM} = fred;
4438c4b7 234no warnings 'syntax' ;
0453d815 235$SIG{TERM} = fred;
599cee73
PM
236EXPECT
237You need to quote "fred" at - line 3.
238########
239# toke.c
4c01a014
BF
240use utf8;
241use open qw( :utf8 :std );
242use warnings 'syntax' ;
243sub frèd {} ; $SIG{TERM} = frèd;
244no warnings 'syntax' ;
245$SIG{TERM} = frèd;
246EXPECT
247You need to quote "frèd" at - line 5.
248########
249# toke.c
250use utf8;
251use open qw( :utf8 :std );
252use warnings 'syntax' ;
253sub ふれど {} ; $SIG{TERM} = ふれど;
254no warnings 'syntax' ;
255$SIG{TERM} = ふれど;
256EXPECT
257You need to quote "ふれど" at - line 5.
258########
259# toke.c
4438c4b7 260use warnings 'syntax' ;
599cee73
PM
261@a[3] = 2;
262@a{3} = 2;
4438c4b7 263no warnings 'syntax' ;
0453d815
PM
264@a[3] = 2;
265@a{3} = 2;
599cee73
PM
266EXPECT
267Scalar value @a[3] better written as $a[3] at - line 3.
268Scalar value @a{3} better written as $a{3} at - line 4.
269########
270# toke.c
b9e186cd
BF
271use utf8;
272use open qw( :utf8 :std );
273use warnings 'syntax' ;
274@à[3] = 2;
275@à{3} = 2;
276no warnings 'syntax' ;
277@à[3] = 2;
278@à{3} = 2;
279EXPECT
280Scalar value @à[3] better written as $à[3] at - line 5.
281Scalar value @à{3} better written as $à{3} at - line 6.
282########
283# toke.c
284use utf8;
285use open qw( :utf8 :std );
286use warnings 'syntax' ;
287@ぁ[3] = 2;
288@ぁ{3} = 2;
289no warnings 'syntax' ;
290@ぁ[3] = 2;
291@ぁ{3} = 2;
292EXPECT
293Scalar value @ぁ[3] better written as $ぁ[3] at - line 5.
294Scalar value @ぁ{3} better written as $ぁ{3} at - line 6.
295########
296# toke.c
4438c4b7 297use warnings 'syntax' ;
599cee73
PM
298$_ = "ab" ;
299s/(ab)/\1/e;
4438c4b7 300no warnings 'syntax' ;
0453d815
PM
301$_ = "ab" ;
302s/(ab)/\1/e;
599cee73
PM
303EXPECT
304Can't use \1 to mean $1 in expression at - line 4.
305########
306# toke.c
4438c4b7 307use warnings 'reserved' ;
599cee73 308$a = abc;
1c3923b3
GS
309$a = { def
310
311=> 1 };
4438c4b7 312no warnings 'reserved' ;
0453d815 313$a = abc;
599cee73
PM
314EXPECT
315Unquoted string "abc" may clash with future reserved word at - line 3.
316########
317# toke.c
e476b1b5 318use warnings 'qw' ;
599cee73 319@a = qw(a, b, c) ;
e476b1b5 320no warnings 'qw' ;
0453d815 321@a = qw(a, b, c) ;
599cee73
PM
322EXPECT
323Possible attempt to separate words with commas at - line 3.
324########
325# toke.c
e476b1b5 326use warnings 'qw' ;
7e03b518 327@a = qw(a b c # #) ;
e476b1b5 328no warnings 'qw' ;
7e03b518 329@a = qw(a b c # #) ;
599cee73
PM
330EXPECT
331Possible attempt to put comments in qw() list at - line 3.
332########
333# toke.c
7e03b518
EB
334use warnings 'qw' ;
335@a = qw(a, b, c # #) ;
336no warnings 'qw' ;
337@a = qw(a, b, c # #) ;
338EXPECT
339Possible attempt to separate words with commas at - line 3.
340Possible attempt to put comments in qw() list at - line 3.
341########
342# toke.c
4438c4b7 343use warnings 'syntax' ;
b1439985
RGS
344print ("");
345print ("") and $x = 1;
346print ("") or die;
347print ("") // die;
348print (1+2) * 3 if 0; # only this one should warn
349print (1+2) if 0;
599cee73 350EXPECT
b1439985 351print (...) interpreted as function at - line 7.
599cee73
PM
352########
353# toke.c
4438c4b7 354no warnings 'syntax' ;
0453d815
PM
355print ("")
356EXPECT
357
358########
359# toke.c
4438c4b7 360use warnings 'syntax' ;
b1439985
RGS
361printf ("");
362printf ("") . '';
599cee73 363EXPECT
b1439985 364printf (...) interpreted as function at - line 4.
599cee73
PM
365########
366# toke.c
4438c4b7 367no warnings 'syntax' ;
0453d815
PM
368printf ("")
369EXPECT
370
371########
372# toke.c
4438c4b7 373use warnings 'syntax' ;
b1439985
RGS
374sort ("");
375sort ("") . '';
599cee73 376EXPECT
b1439985 377sort (...) interpreted as function at - line 4.
599cee73
PM
378########
379# toke.c
4438c4b7 380no warnings 'syntax' ;
0453d815
PM
381sort ("")
382EXPECT
383
384########
385# toke.c
4438c4b7 386use warnings 'ambiguous' ;
599cee73 387$a = ${time[2]};
4438c4b7 388no warnings 'ambiguous' ;
0453d815 389$a = ${time[2]};
599cee73
PM
390EXPECT
391Ambiguous use of ${time[...]} resolved to $time[...] at - line 3.
392########
393# toke.c
4438c4b7 394use warnings 'ambiguous' ;
599cee73
PM
395$a = ${time{2}};
396EXPECT
397Ambiguous use of ${time{...}} resolved to $time{...} at - line 3.
398########
399# toke.c
4438c4b7 400no warnings 'ambiguous' ;
0453d815
PM
401$a = ${time{2}};
402EXPECT
403
404########
405# toke.c
4438c4b7 406use warnings 'ambiguous' ;
599cee73 407$a = ${time} ;
4438c4b7 408no warnings 'ambiguous' ;
0453d815 409$a = ${time} ;
599cee73
PM
410EXPECT
411Ambiguous use of ${time} resolved to $time at - line 3.
412########
413# toke.c
4438c4b7 414use warnings 'ambiguous' ;
599cee73
PM
415sub fred {}
416$a = ${fred} ;
4438c4b7 417no warnings 'ambiguous' ;
0453d815 418$a = ${fred} ;
599cee73
PM
419EXPECT
420Ambiguous use of ${fred} resolved to $fred at - line 4.
421########
422# toke.c
4438c4b7 423use warnings 'syntax' ;
7fd134d9
JH
424$a = _123; print "$a\n"; #( 3 string)
425$a = 1_23; print "$a\n";
426$a = 12_3; print "$a\n";
427$a = 123_; print "$a\n"; # 6
428$a = _+123; print "$a\n"; # 7 string)
429$a = +_123; print "$a\n"; #( 8 string)
430$a = +1_23; print "$a\n";
431$a = +12_3; print "$a\n";
432$a = +123_; print "$a\n"; # 11
433$a = _-123; print "$a\n"; #(12 string)
434$a = -_123; print "$a\n"; #(13 string)
435$a = -1_23; print "$a\n";
436$a = -12_3; print "$a\n";
437$a = -123_; print "$a\n"; # 16
438$a = 123._456; print "$a\n"; # 17
439$a = 123.4_56; print "$a\n";
440$a = 123.45_6; print "$a\n";
441$a = 123.456_; print "$a\n"; # 20
442$a = +123._456; print "$a\n"; # 21
443$a = +123.4_56; print "$a\n";
444$a = +123.45_6; print "$a\n";
445$a = +123.456_; print "$a\n"; # 24
446$a = -123._456; print "$a\n"; # 25
447$a = -123.4_56; print "$a\n";
448$a = -123.45_6; print "$a\n";
449$a = -123.456_; print "$a\n"; # 28
2bea9a37
JH
450$a = 123.456E_12; printf("%.0f\n", $a); # 29
451$a = 123.456E1_2; printf("%.0f\n", $a);
452$a = 123.456E12_; printf("%.0f\n", $a); # 31
453$a = 123.456E_+12; printf("%.0f\n", $a); # 32
454$a = 123.456E+_12; printf("%.0f\n", $a); # 33
455$a = 123.456E+1_2; printf("%.0f\n", $a);
456$a = 123.456E+12_; printf("%.0f\n", $a); # 35
7fd134d9
JH
457$a = 123.456E_-12; print "$a\n"; # 36
458$a = 123.456E-_12; print "$a\n"; # 37
459$a = 123.456E-1_2; print "$a\n";
460$a = 123.456E-12_; print "$a\n"; # 39
b3b48e3e
JH
461$a = 1__23; print "$a\n"; # 40
462$a = 12.3__4; print "$a\n"; # 41
2bea9a37 463$a = 12.34e1__2; printf("%.0f\n", $a); # 42
4438c4b7 464no warnings 'syntax' ;
7fd134d9
JH
465$a = _123; print "$a\n";
466$a = 1_23; print "$a\n";
467$a = 12_3; print "$a\n";
468$a = 123_; print "$a\n";
469$a = _+123; print "$a\n";
470$a = +_123; print "$a\n";
471$a = +1_23; print "$a\n";
472$a = +12_3; print "$a\n";
473$a = +123_; print "$a\n";
474$a = _-123; print "$a\n";
475$a = -_123; print "$a\n";
476$a = -1_23; print "$a\n";
477$a = -12_3; print "$a\n";
478$a = -123_; print "$a\n";
479$a = 123._456; print "$a\n";
480$a = 123.4_56; print "$a\n";
481$a = 123.45_6; print "$a\n";
482$a = 123.456_; print "$a\n";
483$a = +123._456; print "$a\n";
484$a = +123.4_56; print "$a\n";
485$a = +123.45_6; print "$a\n";
486$a = +123.456_; print "$a\n";
487$a = -123._456; print "$a\n";
488$a = -123.4_56; print "$a\n";
489$a = -123.45_6; print "$a\n";
490$a = -123.456_; print "$a\n";
2bea9a37
JH
491$a = 123.456E_12; printf("%.0f\n", $a);
492$a = 123.456E1_2; printf("%.0f\n", $a);
493$a = 123.456E12_; printf("%.0f\n", $a);
494$a = 123.456E_+12; printf("%.0f\n", $a);
495$a = 123.456E+_12; printf("%.0f\n", $a);
496$a = 123.456E+1_2; printf("%.0f\n", $a);
497$a = 123.456E+12_; printf("%.0f\n", $a);
7fd134d9
JH
498$a = 123.456E_-12; print "$a\n";
499$a = 123.456E-_12; print "$a\n";
500$a = 123.456E-1_2; print "$a\n";
501$a = 123.456E-12_; print "$a\n";
b3b48e3e
JH
502$a = 1__23; print "$a\n";
503$a = 12.3__4; print "$a\n";
2bea9a37 504$a = 12.34e1__2; printf("%.0f\n", $a);
599cee73 505EXPECT
fbfa96bd 506OPTIONS regex
928753ea 507Misplaced _ in number at - line 6.
928753ea 508Misplaced _ in number at - line 11.
7fd134d9 509Misplaced _ in number at - line 16.
928753ea 510Misplaced _ in number at - line 17.
7fd134d9 511Misplaced _ in number at - line 20.
928753ea 512Misplaced _ in number at - line 21.
7fd134d9
JH
513Misplaced _ in number at - line 24.
514Misplaced _ in number at - line 25.
515Misplaced _ in number at - line 28.
516Misplaced _ in number at - line 29.
517Misplaced _ in number at - line 31.
518Misplaced _ in number at - line 32.
519Misplaced _ in number at - line 33.
520Misplaced _ in number at - line 35.
521Misplaced _ in number at - line 36.
522Misplaced _ in number at - line 37.
523Misplaced _ in number at - line 39.
b3b48e3e
JH
524Misplaced _ in number at - line 40.
525Misplaced _ in number at - line 41.
526Misplaced _ in number at - line 42.
928753ea
JH
527_123
528123
928753ea 529123
7fd134d9
JH
530123
531123
532_123
533123
534123
535123
536-123
537-_123
538-123
539-123
540-123
541123.456
542123.456
543123.456
544123.456
545123.456
546123.456
547123.456
548123.456
549-123.456
550-123.456
551-123.456
552-123.456
553123456000000000
554123456000000000
555123456000000000
556123456000000000
557123456000000000
558123456000000000
559123456000000000
fbfa96bd
NIS
5601.23456e-0?10
5611.23456e-0?10
5621.23456e-0?10
5631.23456e-0?10
b3b48e3e
JH
564123
56512.34
56612340000000000
7fd134d9
JH
567_123
568123
569123
570123
571123
572_123
573123
574123
575123
576-123
577-_123
578-123
579-123
580-123
581123.456
582123.456
583123.456
584123.456
585123.456
928753ea
JH
586123.456
587123.456
928753ea 588123.456
7fd134d9
JH
589-123.456
590-123.456
591-123.456
592-123.456
593123456000000000
594123456000000000
595123456000000000
596123456000000000
597123456000000000
598123456000000000
599123456000000000
fbfa96bd
NIS
6001.23456e-0?10
6011.23456e-0?10
6021.23456e-0?10
6031.23456e-0?10
b3b48e3e
JH
604123
60512.34
60612340000000000
599cee73
PM
607########
608# toke.c
e476b1b5 609use warnings 'bareword' ;
60e6418e 610#line 25 "bar"
599cee73 611$a = FRED:: ;
e476b1b5 612no warnings 'bareword' ;
0453d815
PM
613#line 25 "bar"
614$a = FRED:: ;
599cee73 615EXPECT
60e6418e 616Bareword "FRED::" refers to nonexistent package at bar line 25.
599cee73
PM
617########
618# toke.c
4438c4b7 619use warnings 'ambiguous' ;
599cee73 620sub time {}
0453d815 621my $a = time() ;
4438c4b7 622no warnings 'ambiguous' ;
0453d815 623my $b = time() ;
599cee73
PM
624EXPECT
625Ambiguous call resolved as CORE::time(), qualify as such or use & at - line 4.
626########
627# toke.c
26d16222 628use warnings ;
0453d815 629eval <<'EOE';
df0deb90
GS
630# line 30 "foo"
631warn "yelp";
0453d815 632{
0453d815
PM
633 $_ = " \x{123} " ;
634}
635EOE
636EXPECT
df0deb90 637yelp at foo line 30.
0453d815
PM
638########
639# toke.c
0453d815
PM
640my $a = rand + 4 ;
641EXPECT
2d5ccbba 642Warning: Use of "rand" without parentheses is ambiguous at - line 2.
0453d815
PM
643########
644# toke.c
645$^W = 0 ;
646my $a = rand + 4 ;
647{
4438c4b7 648 no warnings 'ambiguous' ;
0453d815 649 $a = rand + 4 ;
4438c4b7 650 use warnings 'ambiguous' ;
0453d815
PM
651 $a = rand + 4 ;
652}
653$a = rand + 4 ;
654EXPECT
2d5ccbba
IT
655Warning: Use of "rand" without parentheses is ambiguous at - line 3.
656Warning: Use of "rand" without parentheses is ambiguous at - line 8.
657Warning: Use of "rand" without parentheses is ambiguous at - line 10.
0453d815 658########
e19a021b
FC
659# [perl #97110]
660sub myrand(;$) { }
b5fb7ce3 661sub whatever($) { }
e19a021b 662my $a = myrand + 4 ;
b5fb7ce3 663my $b = whatever + 4 ;
e19a021b 664EXPECT
b5fb7ce3 665Warning: Use of "myrand" without parentheses is ambiguous at - line 4.
e19a021b 666########
0453d815 667# toke.c
e8ae98db
RGS
668use warnings "ambiguous";
669print for keys %+; # should not warn
670EXPECT
671########
672# toke.c
0453d815
PM
673sub fred {};
674-fred ;
675EXPECT
676Ambiguous use of -fred resolved as -&fred() at - line 3.
677########
678# toke.c
679$^W = 0 ;
680sub fred {} ;
681-fred ;
682{
4438c4b7 683 no warnings 'ambiguous' ;
0453d815 684 -fred ;
4438c4b7 685 use warnings 'ambiguous' ;
0453d815
PM
686 -fred ;
687}
688-fred ;
689EXPECT
690Ambiguous use of -fred resolved as -&fred() at - line 4.
691Ambiguous use of -fred resolved as -&fred() at - line 9.
692Ambiguous use of -fred resolved as -&fred() at - line 11.
693########
694# toke.c
695open FOO || time;
240d1b6f 696open local *FOO; # should be ok
0453d815
PM
697EXPECT
698Precedence problem: open FOO should be open(FOO) at - line 2.
699########
66fbe8fb
HS
700# toke.c (and [perl #16184])
701open FOO => "<&0"; close FOO;
702EXPECT
703########
0453d815
PM
704# toke.c
705$^W = 0 ;
706open FOO || time;
707{
e476b1b5 708 no warnings 'precedence' ;
0453d815 709 open FOO || time;
e476b1b5 710 use warnings 'precedence' ;
0453d815
PM
711 open FOO || time;
712}
713open FOO || time;
db3abe52 714open Foo::BAR; # this should not warn
0453d815
PM
715EXPECT
716Precedence problem: open FOO should be open(FOO) at - line 3.
717Precedence problem: open FOO should be open(FOO) at - line 8.
718Precedence problem: open FOO should be open(FOO) at - line 10.
719########
720# toke.c
721$^W = 0 ;
722*foo *foo ;
723{
4438c4b7 724 no warnings 'ambiguous' ;
0453d815 725 *foo *foo ;
4438c4b7 726 use warnings 'ambiguous' ;
0453d815
PM
727 *foo *foo ;
728}
729*foo *foo ;
730EXPECT
731Operator or semicolon missing before *foo at - line 3.
732Ambiguous use of * resolved as operator * at - line 3.
733Operator or semicolon missing before *foo at - line 8.
734Ambiguous use of * resolved as operator * at - line 8.
735Operator or semicolon missing before *foo at - line 10.
736Ambiguous use of * resolved as operator * at - line 10.
767a6a26
PM
737########
738# toke.c
e476b1b5 739use warnings 'misc' ;
767a6a26 740my $a = "\m" ;
e476b1b5 741no warnings 'misc' ;
767a6a26
PM
742$a = "\m" ;
743EXPECT
744Unrecognized escape \m passed through at - line 3.
745########
746# toke.c
52ed07f6
BF
747use warnings 'misc' ;
748my $a = "abcd\E" ;
749no warnings 'misc' ;
750$a = "abcd\E" ;
751EXPECT
820438b1 752Useless use of \E at - line 3.
52ed07f6
BF
753########
754# toke.c
767a6a26
PM
755use warnings 'portable' ;
756my $a = 0b011111111111111111111111111111110 ;
757 $a = 0b011111111111111111111111111111111 ;
758 $a = 0b111111111111111111111111111111111 ;
759 $a = 0x0fffffffe ;
760 $a = 0x0ffffffff ;
761 $a = 0x1ffffffff ;
762 $a = 0037777777776 ;
763 $a = 0037777777777 ;
764 $a = 0047777777777 ;
765no warnings 'portable' ;
766 $a = 0b011111111111111111111111111111110 ;
767 $a = 0b011111111111111111111111111111111 ;
768 $a = 0b111111111111111111111111111111111 ;
769 $a = 0x0fffffffe ;
770 $a = 0x0ffffffff ;
771 $a = 0x1ffffffff ;
772 $a = 0037777777776 ;
773 $a = 0037777777777 ;
774 $a = 0047777777777 ;
775EXPECT
776Binary number > 0b11111111111111111111111111111111 non-portable at - line 5.
777Hexadecimal number > 0xffffffff non-portable at - line 8.
778Octal number > 037777777777 non-portable at - line 11.
779########
780# toke.c
781use warnings 'overflow' ;
782my $a = 0b011111111111111111111111111111110 ;
783 $a = 0b011111111111111111111111111111111 ;
15041a67 784 $a = 0b10000000000000000000000000000000000000000000000000000000000000000 ;
767a6a26
PM
785 $a = 0x0fffffffe ;
786 $a = 0x0ffffffff ;
15041a67 787 $a = 0x10000000000000000 ;
767a6a26
PM
788 $a = 0037777777776 ;
789 $a = 0037777777777 ;
15041a67 790 $a = 002000000000000000000000;
767a6a26
PM
791no warnings 'overflow' ;
792 $a = 0b011111111111111111111111111111110 ;
793 $a = 0b011111111111111111111111111111111 ;
15041a67 794 $a = 0b10000000000000000000000000000000000000000000000000000000000000000 ;
767a6a26
PM
795 $a = 0x0fffffffe ;
796 $a = 0x0ffffffff ;
15041a67 797 $a = 0x10000000000000000 ;
767a6a26
PM
798 $a = 0037777777776 ;
799 $a = 0037777777777 ;
15041a67 800 $a = 002000000000000000000000;
767a6a26
PM
801EXPECT
802Integer overflow in binary number at - line 5.
803Integer overflow in hexadecimal number at - line 8.
804Integer overflow in octal number at - line 11.
8593bda5
GS
805########
806# toke.c
ac206dc8
RGS
807BEGIN { $^C = 1; }
808use warnings 'misc';
809dump;
810CORE::dump;
811EXPECT
812dump() better written as CORE::dump() at - line 4.
813- syntax OK
814########
815# toke.c
816use warnings 'misc';
817use subs qw/dump/;
93f09d7b 818sub dump { print "no warning for overridden dump\n"; }
ac206dc8
RGS
819dump;
820EXPECT
93f09d7b 821no warning for overridden dump
ac206dc8
RGS
822########
823# toke.c
8593bda5
GS
824use warnings 'ambiguous';
825"@mjd_previously_unused_array";
826no warnings 'ambiguous';
827"@mjd_previously_unused_array";
828EXPECT
829Possible unintended interpolation of @mjd_previously_unused_array in string at - line 3.
707afd92
MS
830########
831# toke.c
d8c55666 832# 20020328 mjd-perl-patch+@plover.com at behest of jfriedl@yahoo.com
4ac733c9
MJD
833use warnings 'regexp';
834"foo" =~ /foo/c;
64e578a2 835"foo" =~ /foo/cg;
4ac733c9
MJD
836no warnings 'regexp';
837"foo" =~ /foo/c;
64e578a2 838"foo" =~ /foo/cg;
4ac733c9
MJD
839EXPECT
840Use of /c modifier is meaningless without /g at - line 4.
841########
842# toke.c
d8c55666 843# 20020328 mjd-perl-patch+@plover.com at behest of jfriedl@yahoo.com
4ac733c9
MJD
844use warnings 'regexp';
845$_ = "ab" ;
846s/ab/ab/c;
64e578a2 847s/ab/ab/cg;
4ac733c9
MJD
848no warnings 'regexp';
849s/ab/ab/c;
64e578a2 850s/ab/ab/cg;
4ac733c9 851EXPECT
64e578a2
MJD
852Use of /c modifier is meaningless in s/// at - line 5.
853Use of /c modifier is meaningless in s/// at - line 6.
d8c55666
MJD
854########
855-wa
856# toke.c
857# 20020414 mjd-perl-patch+@plover.com # -a flag should suppress these warnings
858print "@F\n";
859EXPECT
860
861########
862-w
863# toke.c
864# 20020414 mjd-perl-patch+@plover.com # -a flag should suppress these warnings
865print "@F\n";
866EXPECT
867Possible unintended interpolation of @F in string at - line 4.
868Name "main::F" used only once: possible typo at - line 4.
869########
870-wa
871# toke.c
872# 20020414 mjd-perl-patch+@plover.com
873EXPECT
874
2710853f
MJD
875########
876# toke.c
877# 20020414 mjd-perl-patch+@plover.com
878# In 5.7.3, this emitted "Possible unintended interpolation" warnings
879use warnings 'ambiguous';
880$s = "(@-)(@+)";
881EXPECT
882
56da5a46
RGS
883########
884# toke.c
885# mandatory warning
886eval q/if ($a) { } elseif ($b) { }/;
887no warnings "syntax";
888eval q/if ($a) { } elseif ($b) { }/;
889EXPECT
890elseif should be elsif at (eval 1) line 1.
891########
892# toke.c
893# mandatory warning
894eval q/5 6/;
895no warnings "syntax";
896eval q/5 6/;
897EXPECT
898Number found where operator expected at (eval 1) line 1, near "5 6"
899 (Missing operator before 6?)
984200d0
YST
900########
901# toke.c
902use warnings "syntax";
903$_ = $a = 1;
904$a !=~ /1/;
905$a !=~ m#1#;
906$a !=~/1/;
907$a !=~ ?/?;
decca21c
YST
908$a !=~ y/1//;
909$a !=~ tr/1//;
910$a !=~ s/1//;
984200d0
YST
911$a != ~/1/;
912no warnings "syntax";
913$a !=~ /1/;
914$a !=~ m#1#;
915$a !=~/1/;
916$a !=~ ?/?;
decca21c
YST
917$a !=~ y/1//;
918$a !=~ tr/1//;
919$a !=~ s/1//;
984200d0
YST
920EXPECT
921!=~ should be !~ at - line 4.
922!=~ should be !~ at - line 5.
923!=~ should be !~ at - line 6.
924!=~ should be !~ at - line 7.
decca21c
YST
925!=~ should be !~ at - line 8.
926!=~ should be !~ at - line 9.
927!=~ should be !~ at - line 10.
1108974d
RGS
928########
929# toke.c
930our $foo :unique;
8e5dadda
NC
931sub pam :locked;
932sub glipp :locked {
933}
934sub whack_eth ($) : locked {
935}
d1d15184 936no warnings 'deprecated';
1108974d 937our $bar :unique;
8e5dadda
NC
938sub zapeth :locked;
939sub ker_plop :locked {
940}
941sub swa_a_p ($) : locked {
942}
1108974d 943EXPECT
d1d15184
NC
944Use of :unique is deprecated at - line 2.
945Use of :locked is deprecated at - line 3.
946Use of :locked is deprecated at - line 4.
947Use of :locked is deprecated at - line 6.
9e8d7757
RB
948########
949# toke.c
950use warnings "syntax";
951sub proto_after_array(@$);
952sub proto_after_arref(\@$);
953sub proto_after_arref2(\[@$]);
954sub proto_after_arref3(\[@$]_);
955sub proto_after_hash(%$);
956sub proto_after_hashref(\%$);
957sub proto_after_hashref2(\[%$]);
958sub underscore_last_pos($_);
959sub underscore2($_;$);
960sub underscore_fail($_$);
961sub underscore_after_at(@_);
962no warnings "syntax";
963sub proto_after_array(@$);
964sub proto_after_hash(%$);
965sub underscore_fail($_$);
966EXPECT
967Prototype after '@' for main::proto_after_array : @$ at - line 3.
968Prototype after '%' for main::proto_after_hash : %$ at - line 7.
aef2a98a 969Illegal character after '_' in prototype for main::underscore_fail : $_$ at - line 12.
9e8d7757 970Prototype after '@' for main::underscore_after_at : @_ at - line 13.
77772344
B
971########
972# toke.c
973use warnings "ambiguous";
974"foo\nn" =~ /^foo$\n/;
975"foo\nn" =~ /^foo${\}n/;
976my $foo = qr/^foo$\n/;
977my $bar = qr/^foo${\}n/;
978no warnings "ambiguous";
979"foo\nn" =~ /^foo$\n/;
980"foo\nn" =~ /^foo${\}n/;
981my $foo = qr/^foo$\n/;
982my $bar = qr/^foo${\}n/;
983EXPECT
984Possible unintended interpolation of $\ in regex at - line 3.
985Possible unintended interpolation of $\ in regex at - line 5.
d83f38d8
NC
986########
987# toke.c
f0a2b745
KW
988use warnings 'syntax' ;
989my $a = "\o";
990my $a = "\o{";
991my $a = "\o{}";
992no warnings 'syntax' ;
993my $a = "\o";
994my $a = "\o{";
995my $a = "\o{}";
996EXPECT
997Missing braces on \o{} at - line 3, within string
998Missing right brace on \o{ at - line 4, within string
999Number with no digits at - line 5, within string
1000BEGIN not safe after errors--compilation aborted at - line 6.
1001########
1002# toke.c
1003use warnings 'digit' ;
1004my $a = "\o{1238456}";
1005no warnings 'digit' ;
1006my $a = "\o{1238456}";
1007EXPECT
1008Non-octal character '8'. Resolved as "\o{123}" at - line 3.
725a61d7
Z
1009########
1010# toke.c
1011use warnings;
1012my $a = "foo";
1013print $a =~ ?f? ? "yes\n" : "no\n" foreach 0..2;
1014EXPECT
1015Use of ?PATTERN? without explicit operator is deprecated at - line 4.
1016yes
1017no
1018no
17a3df4c
KW
1019########
1020# toke.c
1021use warnings;
1022my $a = "\c{ack}";
1023$a = "\c,";
1024$a = "\c`";
1025no warnings 'syntax';
1026$a = "\c{ack}";
1027$a = "\c,";
1028$a = "\c`";
1029no warnings 'deprecated';
1030EXPECT
1031"\c{" is deprecated and is more clearly written as ";" at - line 3.
1032"\c," is more clearly written simply as "l" at - line 4.
1033"\c`" is more clearly written simply as "\ " at - line 5.
1034"\c{" is deprecated and is more clearly written as ";" at - line 7.
3955e1a9
KW
1035########
1036# toke.c
1037use warnings 'syntax' ;
1038my $a = qr/foo/du;
ff3f26d2 1039$a = qr/foo/lai;
3955e1a9 1040$a = qr/foo/lil;
ff3f26d2
KW
1041$a = qr/foo/aia;
1042$a = qr/foo/aaia;
3955e1a9
KW
1043no warnings 'syntax' ;
1044my $a = qr/foo/du;
1045EXPECT
1046Regexp modifiers "/d" and "/u" are mutually exclusive at - line 3, near "= "
1047Regexp modifiers "/l" and "/a" are mutually exclusive at - line 4, near "= "
1048Regexp modifier "/l" may not appear twice at - line 5, near "= "
ff3f26d2
KW
1049Regexp modifier "/a" may appear a maximum of twice at - line 7, near "= "
1050BEGIN not safe after errors--compilation aborted at - line 8.
ba05d9aa
FC
1051########
1052# toke.c
1053# [perl #4362]
1054eval "print q\xabfoo";
1055print "ok\n" if
1056 $@ =~ /Can't find string terminator "\xab" anywhere before EOF/;
1057EXPECT
1058ok