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