This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
toke.c: 'You need to quote %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
4438c4b7 271use warnings 'syntax' ;
599cee73
PM
272$_ = "ab" ;
273s/(ab)/\1/e;
4438c4b7 274no warnings 'syntax' ;
0453d815
PM
275$_ = "ab" ;
276s/(ab)/\1/e;
599cee73
PM
277EXPECT
278Can't use \1 to mean $1 in expression at - line 4.
279########
280# toke.c
4438c4b7 281use warnings 'reserved' ;
599cee73 282$a = abc;
1c3923b3
GS
283$a = { def
284
285=> 1 };
4438c4b7 286no warnings 'reserved' ;
0453d815 287$a = abc;
599cee73
PM
288EXPECT
289Unquoted string "abc" may clash with future reserved word at - line 3.
290########
291# toke.c
e476b1b5 292use warnings 'qw' ;
599cee73 293@a = qw(a, b, c) ;
e476b1b5 294no warnings 'qw' ;
0453d815 295@a = qw(a, b, c) ;
599cee73
PM
296EXPECT
297Possible attempt to separate words with commas at - line 3.
298########
299# toke.c
e476b1b5 300use warnings 'qw' ;
7e03b518 301@a = qw(a b c # #) ;
e476b1b5 302no warnings 'qw' ;
7e03b518 303@a = qw(a b c # #) ;
599cee73
PM
304EXPECT
305Possible attempt to put comments in qw() list at - line 3.
306########
307# toke.c
7e03b518
EB
308use warnings 'qw' ;
309@a = qw(a, b, c # #) ;
310no warnings 'qw' ;
311@a = qw(a, b, c # #) ;
312EXPECT
313Possible attempt to separate words with commas at - line 3.
314Possible attempt to put comments in qw() list at - line 3.
315########
316# toke.c
4438c4b7 317use warnings 'syntax' ;
b1439985
RGS
318print ("");
319print ("") and $x = 1;
320print ("") or die;
321print ("") // die;
322print (1+2) * 3 if 0; # only this one should warn
323print (1+2) if 0;
599cee73 324EXPECT
b1439985 325print (...) interpreted as function at - line 7.
599cee73
PM
326########
327# toke.c
4438c4b7 328no warnings 'syntax' ;
0453d815
PM
329print ("")
330EXPECT
331
332########
333# toke.c
4438c4b7 334use warnings 'syntax' ;
b1439985
RGS
335printf ("");
336printf ("") . '';
599cee73 337EXPECT
b1439985 338printf (...) interpreted as function at - line 4.
599cee73
PM
339########
340# toke.c
4438c4b7 341no warnings 'syntax' ;
0453d815
PM
342printf ("")
343EXPECT
344
345########
346# toke.c
4438c4b7 347use warnings 'syntax' ;
b1439985
RGS
348sort ("");
349sort ("") . '';
599cee73 350EXPECT
b1439985 351sort (...) interpreted as function at - line 4.
599cee73
PM
352########
353# toke.c
4438c4b7 354no warnings 'syntax' ;
0453d815
PM
355sort ("")
356EXPECT
357
358########
359# toke.c
4438c4b7 360use warnings 'ambiguous' ;
599cee73 361$a = ${time[2]};
4438c4b7 362no warnings 'ambiguous' ;
0453d815 363$a = ${time[2]};
599cee73
PM
364EXPECT
365Ambiguous use of ${time[...]} resolved to $time[...] at - line 3.
366########
367# toke.c
4438c4b7 368use warnings 'ambiguous' ;
599cee73
PM
369$a = ${time{2}};
370EXPECT
371Ambiguous use of ${time{...}} resolved to $time{...} at - line 3.
372########
373# toke.c
4438c4b7 374no warnings 'ambiguous' ;
0453d815
PM
375$a = ${time{2}};
376EXPECT
377
378########
379# toke.c
4438c4b7 380use warnings 'ambiguous' ;
599cee73 381$a = ${time} ;
4438c4b7 382no warnings 'ambiguous' ;
0453d815 383$a = ${time} ;
599cee73
PM
384EXPECT
385Ambiguous use of ${time} resolved to $time at - line 3.
386########
387# toke.c
4438c4b7 388use warnings 'ambiguous' ;
599cee73
PM
389sub fred {}
390$a = ${fred} ;
4438c4b7 391no warnings 'ambiguous' ;
0453d815 392$a = ${fred} ;
599cee73
PM
393EXPECT
394Ambiguous use of ${fred} resolved to $fred at - line 4.
395########
396# toke.c
4438c4b7 397use warnings 'syntax' ;
7fd134d9
JH
398$a = _123; print "$a\n"; #( 3 string)
399$a = 1_23; print "$a\n";
400$a = 12_3; print "$a\n";
401$a = 123_; print "$a\n"; # 6
402$a = _+123; print "$a\n"; # 7 string)
403$a = +_123; print "$a\n"; #( 8 string)
404$a = +1_23; print "$a\n";
405$a = +12_3; print "$a\n";
406$a = +123_; print "$a\n"; # 11
407$a = _-123; print "$a\n"; #(12 string)
408$a = -_123; print "$a\n"; #(13 string)
409$a = -1_23; print "$a\n";
410$a = -12_3; print "$a\n";
411$a = -123_; print "$a\n"; # 16
412$a = 123._456; print "$a\n"; # 17
413$a = 123.4_56; print "$a\n";
414$a = 123.45_6; print "$a\n";
415$a = 123.456_; print "$a\n"; # 20
416$a = +123._456; print "$a\n"; # 21
417$a = +123.4_56; print "$a\n";
418$a = +123.45_6; print "$a\n";
419$a = +123.456_; print "$a\n"; # 24
420$a = -123._456; print "$a\n"; # 25
421$a = -123.4_56; print "$a\n";
422$a = -123.45_6; print "$a\n";
423$a = -123.456_; print "$a\n"; # 28
2bea9a37
JH
424$a = 123.456E_12; printf("%.0f\n", $a); # 29
425$a = 123.456E1_2; printf("%.0f\n", $a);
426$a = 123.456E12_; printf("%.0f\n", $a); # 31
427$a = 123.456E_+12; printf("%.0f\n", $a); # 32
428$a = 123.456E+_12; printf("%.0f\n", $a); # 33
429$a = 123.456E+1_2; printf("%.0f\n", $a);
430$a = 123.456E+12_; printf("%.0f\n", $a); # 35
7fd134d9
JH
431$a = 123.456E_-12; print "$a\n"; # 36
432$a = 123.456E-_12; print "$a\n"; # 37
433$a = 123.456E-1_2; print "$a\n";
434$a = 123.456E-12_; print "$a\n"; # 39
b3b48e3e
JH
435$a = 1__23; print "$a\n"; # 40
436$a = 12.3__4; print "$a\n"; # 41
2bea9a37 437$a = 12.34e1__2; printf("%.0f\n", $a); # 42
4438c4b7 438no warnings 'syntax' ;
7fd134d9
JH
439$a = _123; print "$a\n";
440$a = 1_23; print "$a\n";
441$a = 12_3; print "$a\n";
442$a = 123_; print "$a\n";
443$a = _+123; print "$a\n";
444$a = +_123; print "$a\n";
445$a = +1_23; print "$a\n";
446$a = +12_3; print "$a\n";
447$a = +123_; print "$a\n";
448$a = _-123; print "$a\n";
449$a = -_123; print "$a\n";
450$a = -1_23; print "$a\n";
451$a = -12_3; print "$a\n";
452$a = -123_; print "$a\n";
453$a = 123._456; print "$a\n";
454$a = 123.4_56; print "$a\n";
455$a = 123.45_6; print "$a\n";
456$a = 123.456_; print "$a\n";
457$a = +123._456; print "$a\n";
458$a = +123.4_56; print "$a\n";
459$a = +123.45_6; print "$a\n";
460$a = +123.456_; print "$a\n";
461$a = -123._456; print "$a\n";
462$a = -123.4_56; print "$a\n";
463$a = -123.45_6; print "$a\n";
464$a = -123.456_; print "$a\n";
2bea9a37
JH
465$a = 123.456E_12; printf("%.0f\n", $a);
466$a = 123.456E1_2; printf("%.0f\n", $a);
467$a = 123.456E12_; printf("%.0f\n", $a);
468$a = 123.456E_+12; printf("%.0f\n", $a);
469$a = 123.456E+_12; printf("%.0f\n", $a);
470$a = 123.456E+1_2; printf("%.0f\n", $a);
471$a = 123.456E+12_; printf("%.0f\n", $a);
7fd134d9
JH
472$a = 123.456E_-12; print "$a\n";
473$a = 123.456E-_12; print "$a\n";
474$a = 123.456E-1_2; print "$a\n";
475$a = 123.456E-12_; print "$a\n";
b3b48e3e
JH
476$a = 1__23; print "$a\n";
477$a = 12.3__4; print "$a\n";
2bea9a37 478$a = 12.34e1__2; printf("%.0f\n", $a);
599cee73 479EXPECT
fbfa96bd 480OPTIONS regex
928753ea 481Misplaced _ in number at - line 6.
928753ea 482Misplaced _ in number at - line 11.
7fd134d9 483Misplaced _ in number at - line 16.
928753ea 484Misplaced _ in number at - line 17.
7fd134d9 485Misplaced _ in number at - line 20.
928753ea 486Misplaced _ in number at - line 21.
7fd134d9
JH
487Misplaced _ in number at - line 24.
488Misplaced _ in number at - line 25.
489Misplaced _ in number at - line 28.
490Misplaced _ in number at - line 29.
491Misplaced _ in number at - line 31.
492Misplaced _ in number at - line 32.
493Misplaced _ in number at - line 33.
494Misplaced _ in number at - line 35.
495Misplaced _ in number at - line 36.
496Misplaced _ in number at - line 37.
497Misplaced _ in number at - line 39.
b3b48e3e
JH
498Misplaced _ in number at - line 40.
499Misplaced _ in number at - line 41.
500Misplaced _ in number at - line 42.
928753ea
JH
501_123
502123
928753ea 503123
7fd134d9
JH
504123
505123
506_123
507123
508123
509123
510-123
511-_123
512-123
513-123
514-123
515123.456
516123.456
517123.456
518123.456
519123.456
520123.456
521123.456
522123.456
523-123.456
524-123.456
525-123.456
526-123.456
527123456000000000
528123456000000000
529123456000000000
530123456000000000
531123456000000000
532123456000000000
533123456000000000
fbfa96bd
NIS
5341.23456e-0?10
5351.23456e-0?10
5361.23456e-0?10
5371.23456e-0?10
b3b48e3e
JH
538123
53912.34
54012340000000000
7fd134d9
JH
541_123
542123
543123
544123
545123
546_123
547123
548123
549123
550-123
551-_123
552-123
553-123
554-123
555123.456
556123.456
557123.456
558123.456
559123.456
928753ea
JH
560123.456
561123.456
928753ea 562123.456
7fd134d9
JH
563-123.456
564-123.456
565-123.456
566-123.456
567123456000000000
568123456000000000
569123456000000000
570123456000000000
571123456000000000
572123456000000000
573123456000000000
fbfa96bd
NIS
5741.23456e-0?10
5751.23456e-0?10
5761.23456e-0?10
5771.23456e-0?10
b3b48e3e
JH
578123
57912.34
58012340000000000
599cee73
PM
581########
582# toke.c
e476b1b5 583use warnings 'bareword' ;
60e6418e 584#line 25 "bar"
599cee73 585$a = FRED:: ;
e476b1b5 586no warnings 'bareword' ;
0453d815
PM
587#line 25 "bar"
588$a = FRED:: ;
599cee73 589EXPECT
60e6418e 590Bareword "FRED::" refers to nonexistent package at bar line 25.
599cee73
PM
591########
592# toke.c
4438c4b7 593use warnings 'ambiguous' ;
599cee73 594sub time {}
0453d815 595my $a = time() ;
4438c4b7 596no warnings 'ambiguous' ;
0453d815 597my $b = time() ;
599cee73
PM
598EXPECT
599Ambiguous call resolved as CORE::time(), qualify as such or use & at - line 4.
600########
601# toke.c
26d16222 602use warnings ;
0453d815 603eval <<'EOE';
df0deb90
GS
604# line 30 "foo"
605warn "yelp";
0453d815 606{
0453d815
PM
607 $_ = " \x{123} " ;
608}
609EOE
610EXPECT
df0deb90 611yelp at foo line 30.
0453d815
PM
612########
613# toke.c
0453d815
PM
614my $a = rand + 4 ;
615EXPECT
2d5ccbba 616Warning: Use of "rand" without parentheses is ambiguous at - line 2.
0453d815
PM
617########
618# toke.c
619$^W = 0 ;
620my $a = rand + 4 ;
621{
4438c4b7 622 no warnings 'ambiguous' ;
0453d815 623 $a = rand + 4 ;
4438c4b7 624 use warnings 'ambiguous' ;
0453d815
PM
625 $a = rand + 4 ;
626}
627$a = rand + 4 ;
628EXPECT
2d5ccbba
IT
629Warning: Use of "rand" without parentheses is ambiguous at - line 3.
630Warning: Use of "rand" without parentheses is ambiguous at - line 8.
631Warning: Use of "rand" without parentheses is ambiguous at - line 10.
0453d815 632########
e19a021b
FC
633# [perl #97110]
634sub myrand(;$) { }
b5fb7ce3 635sub whatever($) { }
e19a021b 636my $a = myrand + 4 ;
b5fb7ce3 637my $b = whatever + 4 ;
e19a021b 638EXPECT
b5fb7ce3 639Warning: Use of "myrand" without parentheses is ambiguous at - line 4.
e19a021b 640########
0453d815 641# toke.c
e8ae98db
RGS
642use warnings "ambiguous";
643print for keys %+; # should not warn
644EXPECT
645########
646# toke.c
0453d815
PM
647sub fred {};
648-fred ;
649EXPECT
650Ambiguous use of -fred resolved as -&fred() at - line 3.
651########
652# toke.c
653$^W = 0 ;
654sub fred {} ;
655-fred ;
656{
4438c4b7 657 no warnings 'ambiguous' ;
0453d815 658 -fred ;
4438c4b7 659 use warnings 'ambiguous' ;
0453d815
PM
660 -fred ;
661}
662-fred ;
663EXPECT
664Ambiguous use of -fred resolved as -&fred() at - line 4.
665Ambiguous use of -fred resolved as -&fred() at - line 9.
666Ambiguous use of -fred resolved as -&fred() at - line 11.
667########
668# toke.c
669open FOO || time;
240d1b6f 670open local *FOO; # should be ok
0453d815
PM
671EXPECT
672Precedence problem: open FOO should be open(FOO) at - line 2.
673########
66fbe8fb
HS
674# toke.c (and [perl #16184])
675open FOO => "<&0"; close FOO;
676EXPECT
677########
0453d815
PM
678# toke.c
679$^W = 0 ;
680open FOO || time;
681{
e476b1b5 682 no warnings 'precedence' ;
0453d815 683 open FOO || time;
e476b1b5 684 use warnings 'precedence' ;
0453d815
PM
685 open FOO || time;
686}
687open FOO || time;
db3abe52 688open Foo::BAR; # this should not warn
0453d815
PM
689EXPECT
690Precedence problem: open FOO should be open(FOO) at - line 3.
691Precedence problem: open FOO should be open(FOO) at - line 8.
692Precedence problem: open FOO should be open(FOO) at - line 10.
693########
694# toke.c
695$^W = 0 ;
696*foo *foo ;
697{
4438c4b7 698 no warnings 'ambiguous' ;
0453d815 699 *foo *foo ;
4438c4b7 700 use warnings 'ambiguous' ;
0453d815
PM
701 *foo *foo ;
702}
703*foo *foo ;
704EXPECT
705Operator or semicolon missing before *foo at - line 3.
706Ambiguous use of * resolved as operator * at - line 3.
707Operator or semicolon missing before *foo at - line 8.
708Ambiguous use of * resolved as operator * at - line 8.
709Operator or semicolon missing before *foo at - line 10.
710Ambiguous use of * resolved as operator * at - line 10.
767a6a26
PM
711########
712# toke.c
e476b1b5 713use warnings 'misc' ;
767a6a26 714my $a = "\m" ;
e476b1b5 715no warnings 'misc' ;
767a6a26
PM
716$a = "\m" ;
717EXPECT
718Unrecognized escape \m passed through at - line 3.
719########
720# toke.c
52ed07f6
BF
721use warnings 'misc' ;
722my $a = "abcd\E" ;
723no warnings 'misc' ;
724$a = "abcd\E" ;
725EXPECT
820438b1 726Useless use of \E at - line 3.
52ed07f6
BF
727########
728# toke.c
767a6a26
PM
729use warnings 'portable' ;
730my $a = 0b011111111111111111111111111111110 ;
731 $a = 0b011111111111111111111111111111111 ;
732 $a = 0b111111111111111111111111111111111 ;
733 $a = 0x0fffffffe ;
734 $a = 0x0ffffffff ;
735 $a = 0x1ffffffff ;
736 $a = 0037777777776 ;
737 $a = 0037777777777 ;
738 $a = 0047777777777 ;
739no warnings 'portable' ;
740 $a = 0b011111111111111111111111111111110 ;
741 $a = 0b011111111111111111111111111111111 ;
742 $a = 0b111111111111111111111111111111111 ;
743 $a = 0x0fffffffe ;
744 $a = 0x0ffffffff ;
745 $a = 0x1ffffffff ;
746 $a = 0037777777776 ;
747 $a = 0037777777777 ;
748 $a = 0047777777777 ;
749EXPECT
750Binary number > 0b11111111111111111111111111111111 non-portable at - line 5.
751Hexadecimal number > 0xffffffff non-portable at - line 8.
752Octal number > 037777777777 non-portable at - line 11.
753########
754# toke.c
755use warnings 'overflow' ;
756my $a = 0b011111111111111111111111111111110 ;
757 $a = 0b011111111111111111111111111111111 ;
15041a67 758 $a = 0b10000000000000000000000000000000000000000000000000000000000000000 ;
767a6a26
PM
759 $a = 0x0fffffffe ;
760 $a = 0x0ffffffff ;
15041a67 761 $a = 0x10000000000000000 ;
767a6a26
PM
762 $a = 0037777777776 ;
763 $a = 0037777777777 ;
15041a67 764 $a = 002000000000000000000000;
767a6a26
PM
765no warnings 'overflow' ;
766 $a = 0b011111111111111111111111111111110 ;
767 $a = 0b011111111111111111111111111111111 ;
15041a67 768 $a = 0b10000000000000000000000000000000000000000000000000000000000000000 ;
767a6a26
PM
769 $a = 0x0fffffffe ;
770 $a = 0x0ffffffff ;
15041a67 771 $a = 0x10000000000000000 ;
767a6a26
PM
772 $a = 0037777777776 ;
773 $a = 0037777777777 ;
15041a67 774 $a = 002000000000000000000000;
767a6a26
PM
775EXPECT
776Integer overflow in binary number at - line 5.
777Integer overflow in hexadecimal number at - line 8.
778Integer overflow in octal number at - line 11.
8593bda5
GS
779########
780# toke.c
ac206dc8
RGS
781BEGIN { $^C = 1; }
782use warnings 'misc';
783dump;
784CORE::dump;
785EXPECT
786dump() better written as CORE::dump() at - line 4.
787- syntax OK
788########
789# toke.c
790use warnings 'misc';
791use subs qw/dump/;
93f09d7b 792sub dump { print "no warning for overridden dump\n"; }
ac206dc8
RGS
793dump;
794EXPECT
93f09d7b 795no warning for overridden dump
ac206dc8
RGS
796########
797# toke.c
8593bda5
GS
798use warnings 'ambiguous';
799"@mjd_previously_unused_array";
800no warnings 'ambiguous';
801"@mjd_previously_unused_array";
802EXPECT
803Possible unintended interpolation of @mjd_previously_unused_array in string at - line 3.
707afd92
MS
804########
805# toke.c
d8c55666 806# 20020328 mjd-perl-patch+@plover.com at behest of jfriedl@yahoo.com
4ac733c9
MJD
807use warnings 'regexp';
808"foo" =~ /foo/c;
64e578a2 809"foo" =~ /foo/cg;
4ac733c9
MJD
810no warnings 'regexp';
811"foo" =~ /foo/c;
64e578a2 812"foo" =~ /foo/cg;
4ac733c9
MJD
813EXPECT
814Use of /c modifier is meaningless without /g at - line 4.
815########
816# toke.c
d8c55666 817# 20020328 mjd-perl-patch+@plover.com at behest of jfriedl@yahoo.com
4ac733c9
MJD
818use warnings 'regexp';
819$_ = "ab" ;
820s/ab/ab/c;
64e578a2 821s/ab/ab/cg;
4ac733c9
MJD
822no warnings 'regexp';
823s/ab/ab/c;
64e578a2 824s/ab/ab/cg;
4ac733c9 825EXPECT
64e578a2
MJD
826Use of /c modifier is meaningless in s/// at - line 5.
827Use of /c modifier is meaningless in s/// at - line 6.
d8c55666
MJD
828########
829-wa
830# toke.c
831# 20020414 mjd-perl-patch+@plover.com # -a flag should suppress these warnings
832print "@F\n";
833EXPECT
834
835########
836-w
837# toke.c
838# 20020414 mjd-perl-patch+@plover.com # -a flag should suppress these warnings
839print "@F\n";
840EXPECT
841Possible unintended interpolation of @F in string at - line 4.
842Name "main::F" used only once: possible typo at - line 4.
843########
844-wa
845# toke.c
846# 20020414 mjd-perl-patch+@plover.com
847EXPECT
848
2710853f
MJD
849########
850# toke.c
851# 20020414 mjd-perl-patch+@plover.com
852# In 5.7.3, this emitted "Possible unintended interpolation" warnings
853use warnings 'ambiguous';
854$s = "(@-)(@+)";
855EXPECT
856
56da5a46
RGS
857########
858# toke.c
859# mandatory warning
860eval q/if ($a) { } elseif ($b) { }/;
861no warnings "syntax";
862eval q/if ($a) { } elseif ($b) { }/;
863EXPECT
864elseif should be elsif at (eval 1) line 1.
865########
866# toke.c
867# mandatory warning
868eval q/5 6/;
869no warnings "syntax";
870eval q/5 6/;
871EXPECT
872Number found where operator expected at (eval 1) line 1, near "5 6"
873 (Missing operator before 6?)
984200d0
YST
874########
875# toke.c
876use warnings "syntax";
877$_ = $a = 1;
878$a !=~ /1/;
879$a !=~ m#1#;
880$a !=~/1/;
881$a !=~ ?/?;
decca21c
YST
882$a !=~ y/1//;
883$a !=~ tr/1//;
884$a !=~ s/1//;
984200d0
YST
885$a != ~/1/;
886no warnings "syntax";
887$a !=~ /1/;
888$a !=~ m#1#;
889$a !=~/1/;
890$a !=~ ?/?;
decca21c
YST
891$a !=~ y/1//;
892$a !=~ tr/1//;
893$a !=~ s/1//;
984200d0
YST
894EXPECT
895!=~ should be !~ at - line 4.
896!=~ should be !~ at - line 5.
897!=~ should be !~ at - line 6.
898!=~ should be !~ at - line 7.
decca21c
YST
899!=~ should be !~ at - line 8.
900!=~ should be !~ at - line 9.
901!=~ should be !~ at - line 10.
1108974d
RGS
902########
903# toke.c
904our $foo :unique;
8e5dadda
NC
905sub pam :locked;
906sub glipp :locked {
907}
908sub whack_eth ($) : locked {
909}
d1d15184 910no warnings 'deprecated';
1108974d 911our $bar :unique;
8e5dadda
NC
912sub zapeth :locked;
913sub ker_plop :locked {
914}
915sub swa_a_p ($) : locked {
916}
1108974d 917EXPECT
d1d15184
NC
918Use of :unique is deprecated at - line 2.
919Use of :locked is deprecated at - line 3.
920Use of :locked is deprecated at - line 4.
921Use of :locked is deprecated at - line 6.
9e8d7757
RB
922########
923# toke.c
924use warnings "syntax";
925sub proto_after_array(@$);
926sub proto_after_arref(\@$);
927sub proto_after_arref2(\[@$]);
928sub proto_after_arref3(\[@$]_);
929sub proto_after_hash(%$);
930sub proto_after_hashref(\%$);
931sub proto_after_hashref2(\[%$]);
932sub underscore_last_pos($_);
933sub underscore2($_;$);
934sub underscore_fail($_$);
935sub underscore_after_at(@_);
936no warnings "syntax";
937sub proto_after_array(@$);
938sub proto_after_hash(%$);
939sub underscore_fail($_$);
940EXPECT
941Prototype after '@' for main::proto_after_array : @$ at - line 3.
942Prototype after '%' for main::proto_after_hash : %$ at - line 7.
aef2a98a 943Illegal character after '_' in prototype for main::underscore_fail : $_$ at - line 12.
9e8d7757 944Prototype after '@' for main::underscore_after_at : @_ at - line 13.
77772344
B
945########
946# toke.c
947use warnings "ambiguous";
948"foo\nn" =~ /^foo$\n/;
949"foo\nn" =~ /^foo${\}n/;
950my $foo = qr/^foo$\n/;
951my $bar = qr/^foo${\}n/;
952no warnings "ambiguous";
953"foo\nn" =~ /^foo$\n/;
954"foo\nn" =~ /^foo${\}n/;
955my $foo = qr/^foo$\n/;
956my $bar = qr/^foo${\}n/;
957EXPECT
958Possible unintended interpolation of $\ in regex at - line 3.
959Possible unintended interpolation of $\ in regex at - line 5.
d83f38d8
NC
960########
961# toke.c
f0a2b745
KW
962use warnings 'syntax' ;
963my $a = "\o";
964my $a = "\o{";
965my $a = "\o{}";
966no warnings 'syntax' ;
967my $a = "\o";
968my $a = "\o{";
969my $a = "\o{}";
970EXPECT
971Missing braces on \o{} at - line 3, within string
972Missing right brace on \o{ at - line 4, within string
973Number with no digits at - line 5, within string
974BEGIN not safe after errors--compilation aborted at - line 6.
975########
976# toke.c
977use warnings 'digit' ;
978my $a = "\o{1238456}";
979no warnings 'digit' ;
980my $a = "\o{1238456}";
981EXPECT
982Non-octal character '8'. Resolved as "\o{123}" at - line 3.
725a61d7
Z
983########
984# toke.c
985use warnings;
986my $a = "foo";
987print $a =~ ?f? ? "yes\n" : "no\n" foreach 0..2;
988EXPECT
989Use of ?PATTERN? without explicit operator is deprecated at - line 4.
990yes
991no
992no
17a3df4c
KW
993########
994# toke.c
995use warnings;
996my $a = "\c{ack}";
997$a = "\c,";
998$a = "\c`";
999no warnings 'syntax';
1000$a = "\c{ack}";
1001$a = "\c,";
1002$a = "\c`";
1003no warnings 'deprecated';
1004EXPECT
1005"\c{" is deprecated and is more clearly written as ";" at - line 3.
1006"\c," is more clearly written simply as "l" at - line 4.
1007"\c`" is more clearly written simply as "\ " at - line 5.
1008"\c{" is deprecated and is more clearly written as ";" at - line 7.
3955e1a9
KW
1009########
1010# toke.c
1011use warnings 'syntax' ;
1012my $a = qr/foo/du;
ff3f26d2 1013$a = qr/foo/lai;
3955e1a9 1014$a = qr/foo/lil;
ff3f26d2
KW
1015$a = qr/foo/aia;
1016$a = qr/foo/aaia;
3955e1a9
KW
1017no warnings 'syntax' ;
1018my $a = qr/foo/du;
1019EXPECT
1020Regexp modifiers "/d" and "/u" are mutually exclusive at - line 3, near "= "
1021Regexp modifiers "/l" and "/a" are mutually exclusive at - line 4, near "= "
1022Regexp modifier "/l" may not appear twice at - line 5, near "= "
ff3f26d2
KW
1023Regexp modifier "/a" may appear a maximum of twice at - line 7, near "= "
1024BEGIN not safe after errors--compilation aborted at - line 8.
ba05d9aa
FC
1025########
1026# toke.c
1027# [perl #4362]
1028eval "print q\xabfoo";
1029print "ok\n" if
1030 $@ =~ /Can't find string terminator "\xab" anywhere before EOF/;
1031EXPECT
1032ok