partly fix perldiag regressions identified by Tom Christiansen
[p5sagit/p5-mst-13.2.git] / t / pragma / warn / toke
1 toke.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 
17         use warnings 'syntax' ;
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"
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 ;
124      
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
140 __END__
141 # toke.c 
142 use warnings 'deprecated' ;
143 1 if $a EQ $b ;
144 1 if $a NE $b ;
145 1 if $a GT $b ;
146 1 if $a LT $b ;
147 1 if $a GE $b ;
148 1 if $a LE $b ;
149 no warnings 'deprecated' ;
150 1 if $a EQ $b ;
151 1 if $a NE $b ;
152 1 if $a GT $b ;
153 1 if $a LT $b ;
154 1 if $a GE $b ;
155 1 if $a LE $b ;
156 EXPECT
157 Use of EQ is deprecated at - line 3.
158 Use of NE is deprecated at - line 4.
159 Use of GT is deprecated at - line 5.
160 Use of LT is deprecated at - line 6.
161 Use of GE is deprecated at - line 7.
162 Use of LE is deprecated at - line 8.
163 ########
164 # toke.c
165 use warnings 'deprecated' ;
166 format STDOUT =
167 @<<<  @|||  @>>>  @>>>
168 $a    $b    "abc" 'def'
169 .
170 no warnings 'deprecated' ;
171 format STDOUT =
172 @<<<  @|||  @>>>  @>>>
173 $a    $b    "abc" 'def'
174 .
175 EXPECT
176 Use of comma-less variable list is deprecated at - line 5.
177 Use of comma-less variable list is deprecated at - line 5.
178 Use of comma-less variable list is deprecated at - line 5.
179 ########
180 # toke.c
181 use warnings 'deprecated' ;
182 $a = <<;
183
184 no warnings 'deprecated' ;
185 $a = <<;
186
187 EXPECT
188 Use of bare << to mean <<"" is deprecated at - line 3.
189 ########
190 # toke.c
191 use warnings 'syntax' ;
192 s/(abc)/\1/;
193 no warnings 'syntax' ;
194 s/(abc)/\1/;
195 EXPECT
196 \1 better written as $1 at - line 3.
197 ########
198 # toke.c
199 use warnings 'semicolon' ;
200 $a = 1
201 &time ;
202 no warnings 'semicolon' ;
203 $a = 1
204 &time ;
205 EXPECT
206 Semicolon seems to be missing at - line 3.
207 ########
208 # toke.c
209 BEGIN {
210     # Scalars leaked: due to syntax errors
211     $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
212 }
213 use warnings 'syntax' ;
214 my $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 ;
224 EXPECT
225 Reversed += operator at - line 7.
226 Reversed -= operator at - line 8.
227 Reversed *= operator at - line 9.
228 Reversed %= operator at - line 10.
229 Reversed &= operator at - line 11.
230 Reversed .= operator at - line 12.
231 syntax error at - line 12, near "=."
232 Reversed ^= operator at - line 13.
233 syntax error at - line 13, near "=^"
234 Reversed |= operator at - line 14.
235 syntax error at - line 14, near "=|"
236 Reversed <= operator at - line 15.
237 Unterminated <> operator at - line 15.
238 ########
239 # toke.c
240 BEGIN {
241     # Scalars leaked: due to syntax errors
242     $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
243 }
244 no warnings 'syntax' ;
245 my $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 ;
255 EXPECT
256 syntax error at - line 12, near "=."
257 syntax error at - line 13, near "=^"
258 syntax error at - line 14, near "=|"
259 Unterminated <> operator at - line 15.
260 ########
261 # toke.c
262 use warnings 'syntax' ;
263 my $a = $a[1,2] ;
264 no warnings 'syntax' ;
265 my $a = $a[1,2] ;
266 EXPECT
267 Multidimensional syntax $a[1,2] not supported at - line 3.
268 ########
269 # toke.c
270 use warnings 'syntax' ;
271 sub fred {} ; $SIG{TERM} = fred;
272 no warnings 'syntax' ;
273 $SIG{TERM} = fred;
274 EXPECT
275 You need to quote "fred" at - line 3.
276 ########
277 # toke.c
278 use warnings 'syntax' ;
279 @a[3] = 2;
280 @a{3} = 2;
281 no warnings 'syntax' ;
282 @a[3] = 2;
283 @a{3} = 2;
284 EXPECT
285 Scalar value @a[3] better written as $a[3] at - line 3.
286 Scalar value @a{3} better written as $a{3} at - line 4.
287 ########
288 # toke.c
289 use warnings 'syntax' ;
290 $_ = "ab" ; 
291 s/(ab)/\1/e;
292 no warnings 'syntax' ;
293 $_ = "ab" ; 
294 s/(ab)/\1/e;
295 EXPECT
296 Can't use \1 to mean $1 in expression at - line 4.
297 ########
298 # toke.c
299 use warnings 'reserved' ;
300 $a = abc;
301 no warnings 'reserved' ;
302 $a = abc;
303 EXPECT
304 Unquoted string "abc" may clash with future reserved word at - line 3.
305 ########
306 # toke.c
307 use warnings 'octal' ;
308 chmod 3;
309 no warnings 'octal' ;
310 chmod 3;
311 EXPECT
312 chmod: mode argument is missing initial 0 at - line 3.
313 ########
314 # toke.c
315 use warnings 'syntax' ;
316 @a = qw(a, b, c) ;
317 no warnings 'syntax' ;
318 @a = qw(a, b, c) ;
319 EXPECT
320 Possible attempt to separate words with commas at - line 3.
321 ########
322 # toke.c
323 use warnings 'syntax' ;
324 @a = qw(a b #) ;
325 no warnings 'syntax' ;
326 @a = qw(a b #) ;
327 EXPECT
328 Possible attempt to put comments in qw() list at - line 3.
329 ########
330 # toke.c
331 use warnings 'octal' ;
332 umask 3;
333 no warnings 'octal' ;
334 umask 3;
335 EXPECT
336 umask: argument is missing initial 0 at - line 3.
337 ########
338 # toke.c
339 use warnings 'syntax' ;
340 print ("")
341 EXPECT
342 print (...) interpreted as function at - line 3.
343 ########
344 # toke.c
345 no warnings 'syntax' ;
346 print ("")
347 EXPECT
348
349 ########
350 # toke.c
351 use warnings 'syntax' ;
352 printf ("")
353 EXPECT
354 printf (...) interpreted as function at - line 3.
355 ########
356 # toke.c
357 no warnings 'syntax' ;
358 printf ("")
359 EXPECT
360
361 ########
362 # toke.c
363 use warnings 'syntax' ;
364 sort ("")
365 EXPECT
366 sort (...) interpreted as function at - line 3.
367 ########
368 # toke.c
369 no warnings 'syntax' ;
370 sort ("")
371 EXPECT
372
373 ########
374 # toke.c
375 use warnings 'ambiguous' ;
376 $a = ${time[2]};
377 no warnings 'ambiguous' ;
378 $a = ${time[2]};
379 EXPECT
380 Ambiguous use of ${time[...]} resolved to $time[...] at - line 3.
381 ########
382 # toke.c
383 use warnings 'ambiguous' ;
384 $a = ${time{2}};
385 EXPECT
386 Ambiguous use of ${time{...}} resolved to $time{...} at - line 3.
387 ########
388 # toke.c
389 no warnings 'ambiguous' ;
390 $a = ${time{2}};
391 EXPECT
392
393 ########
394 # toke.c
395 use warnings 'ambiguous' ;
396 $a = ${time} ;
397 no warnings 'ambiguous' ;
398 $a = ${time} ;
399 EXPECT
400 Ambiguous use of ${time} resolved to $time at - line 3.
401 ########
402 # toke.c
403 use warnings 'ambiguous' ;
404 sub fred {}
405 $a = ${fred} ;
406 no warnings 'ambiguous' ;
407 $a = ${fred} ;
408 EXPECT
409 Ambiguous use of ${fred} resolved to $fred at - line 4.
410 ########
411 # toke.c
412 use warnings 'syntax' ;
413 $a = 1_2;
414 $a = 1_2345_6;
415 no warnings 'syntax' ;
416 $a = 1_2;
417 $a = 1_2345_6;
418 EXPECT
419 Misplaced _ in number at - line 3.
420 Misplaced _ in number at - line 4.
421 Misplaced _ in number at - line 4.
422 ########
423 # toke.c
424 use warnings 'unsafe' ;
425 #line 25 "bar"
426 $a = FRED:: ;
427 no warnings 'unsafe' ;
428 #line 25 "bar"
429 $a = FRED:: ;
430 EXPECT
431 Bareword "FRED::" refers to nonexistent package at bar line 25.
432 ########
433 # toke.c
434 use warnings 'ambiguous' ;
435 sub time {}
436 my $a = time() ;
437 no warnings 'ambiguous' ;
438 my $b = time() ;
439 EXPECT
440 Ambiguous call resolved as CORE::time(), qualify as such or use & at - line 4.
441 ########
442 # toke.c
443 use warnings 'utf8' ;
444 eval <<'EOE';
445 {
446 #line 30 "foo"
447   $_ = " \x{123} " ;
448 }
449 EOE
450 EXPECT
451 Use of \x{} without utf8 declaration at foo line 30.
452 ########
453 # toke.c
454 no warnings 'utf8' ;
455 eval <<'EOE';
456 {
457 #line 30 "foo"
458   $_ = " \x{123} " ;
459 }
460 EOE
461 EXPECT
462
463 ########
464 # toke.c
465 use warnings 'utf8' ;
466 use utf8 ;
467 $_ = " \xffe " ;
468 no warnings 'utf8' ;
469 $_ = " \xffe " ;
470 EXPECT
471 \xff will produce malformed UTF-8 character; use \x{ff} for that at - line 4.
472 ########
473 # toke.c
474 my $a = rand + 4 ;
475 EXPECT
476 Warning: Use of "rand" without parens is ambiguous at - line 2.
477 ########
478 # toke.c
479 $^W = 0 ;
480 my $a = rand + 4 ;
481 {
482     no warnings 'ambiguous' ;
483     $a = rand + 4 ;
484     use warnings 'ambiguous' ;
485     $a = rand + 4 ;
486 }
487 $a = rand + 4 ;
488 EXPECT
489 Warning: Use of "rand" without parens is ambiguous at - line 3.
490 Warning: Use of "rand" without parens is ambiguous at - line 8.
491 Warning: Use of "rand" without parens is ambiguous at - line 10.
492 ########
493 # toke.c
494 sub fred {};
495 -fred ;
496 EXPECT
497 Ambiguous use of -fred resolved as -&fred() at - line 3.
498 ########
499 # toke.c
500 $^W = 0 ;
501 sub fred {} ;
502 -fred ;
503 {
504     no warnings 'ambiguous' ;
505     -fred ;
506     use warnings 'ambiguous' ;
507     -fred ;
508 }
509 -fred ;
510 EXPECT
511 Ambiguous use of -fred resolved as -&fred() at - line 4.
512 Ambiguous use of -fred resolved as -&fred() at - line 9.
513 Ambiguous use of -fred resolved as -&fred() at - line 11.
514 ########
515 # toke.c
516 open FOO || time;
517 EXPECT
518 Precedence problem: open FOO should be open(FOO) at - line 2.
519 ########
520 # toke.c
521 $^W = 0 ;
522 open FOO || time;
523 {
524     no warnings 'ambiguous' ;
525     open FOO || time;
526     use warnings 'ambiguous' ;
527     open FOO || time;
528 }
529 open FOO || time;
530 EXPECT
531 Precedence problem: open FOO should be open(FOO) at - line 3.
532 Precedence problem: open FOO should be open(FOO) at - line 8.
533 Precedence problem: open FOO should be open(FOO) at - line 10.
534 ########
535 # toke.c
536 $^W = 0 ;
537 *foo *foo ;
538 {
539     no warnings 'ambiguous' ;
540     *foo *foo ;
541     use warnings 'ambiguous' ;
542     *foo *foo ;
543 }
544 *foo *foo ;
545 EXPECT
546 Operator or semicolon missing before *foo at - line 3.
547 Ambiguous use of * resolved as operator * at - line 3.
548 Operator or semicolon missing before *foo at - line 8.
549 Ambiguous use of * resolved as operator * at - line 8.
550 Operator or semicolon missing before *foo at - line 10.
551 Ambiguous use of * resolved as operator * at - line 10.
552 ########
553 # toke.c
554 use warnings 'unsafe' ;
555 my $a = "\m" ;
556 no warnings 'unsafe' ;
557 $a = "\m" ;
558 EXPECT
559 Unrecognized escape \m passed through at - line 3.
560 ########
561 # toke.c
562 use warnings 'portable' ;
563 my $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 ;
572 no 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 ;
582 EXPECT
583 Binary number > 0b11111111111111111111111111111111 non-portable at - line 5.
584 Hexadecimal number > 0xffffffff non-portable at - line 8.
585 Octal number > 037777777777 non-portable at - line 11.
586 ########
587 # toke.c
588 use warnings 'overflow' ;
589 my $a =  0b011111111111111111111111111111110 ;
590    $a =  0b011111111111111111111111111111111 ;
591    $a =  0b10000000000000000000000000000000000000000000000000000000000000000 ;
592    $a =  0x0fffffffe ;
593    $a =  0x0ffffffff ;
594    $a =  0x10000000000000000 ;
595    $a =  0037777777776 ;
596    $a =  0037777777777 ;
597    $a =  002000000000000000000000;
598 no warnings 'overflow' ;
599    $a =  0b011111111111111111111111111111110 ;
600    $a =  0b011111111111111111111111111111111 ;
601    $a =  0b10000000000000000000000000000000000000000000000000000000000000000 ;
602    $a =  0x0fffffffe ;
603    $a =  0x0ffffffff ;
604    $a =  0x10000000000000000 ;
605    $a =  0037777777776 ;
606    $a =  0037777777777 ;
607    $a =  002000000000000000000000;
608 EXPECT
609 Integer overflow in binary number at - line 5.
610 Integer overflow in hexadecimal number at - line 8.
611 Integer overflow in octal number at - line 11.