improvements for high-bit text literals (from Gisle Aas)
[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     Unrecognized escape \\%c passed through
93         $a = "\m" ;
94
95     %s number > %s non-portable
96         my $a =  0b011111111111111111111111111111110 ;
97         $a =  0b011111111111111111111111111111111 ;
98         $a =  0b111111111111111111111111111111111 ;
99         $a =  0x0fffffffe ;
100         $a =  0x0ffffffff ;
101         $a =  0x1ffffffff ;
102         $a =  0037777777776 ;
103         $a =  0037777777777 ;
104         $a =  0047777777777 ;
105
106     Integer overflow in binary number
107         my $a =  0b011111111111111111111111111111110 ;
108         $a =  0b011111111111111111111111111111111 ;
109         $a =  0b111111111111111111111111111111111 ;
110         $a =  0x0fffffffe ;
111         $a =  0x0ffffffff ;
112         $a =  0x1ffffffff ;
113         $a =  0037777777776 ;
114         $a =  0037777777777 ;
115         $a =  0047777777777 ;
116      
117     Mandatory Warnings
118     ------------------
119     Use of "%s" without parentheses is ambiguous        [check_uni]
120         rand + 4 
121
122     Ambiguous use of -%s resolved as -&%s()             [yylex]
123         sub fred {} ; - fred ;
124
125     Precedence problem: open %.*s should be open(%.*s)  [yylex]
126         open FOO || die;
127
128     Operator or semicolon missing before %c%s           [yylex]
129     Ambiguous use of %c resolved as operator %c
130         *foo *foo
131
132 __END__
133 # toke.c 
134 use warnings 'deprecated' ;
135 1 if $a EQ $b ;
136 1 if $a NE $b ;
137 1 if $a GT $b ;
138 1 if $a LT $b ;
139 1 if $a GE $b ;
140 1 if $a LE $b ;
141 no warnings 'deprecated' ;
142 1 if $a EQ $b ;
143 1 if $a NE $b ;
144 1 if $a GT $b ;
145 1 if $a LT $b ;
146 1 if $a GE $b ;
147 1 if $a LE $b ;
148 EXPECT
149 Use of EQ is deprecated at - line 3.
150 Use of NE is deprecated at - line 4.
151 Use of GT is deprecated at - line 5.
152 Use of LT is deprecated at - line 6.
153 Use of GE is deprecated at - line 7.
154 Use of LE is deprecated at - line 8.
155 ########
156 # toke.c
157 use warnings 'deprecated' ;
158 format STDOUT =
159 @<<<  @|||  @>>>  @>>>
160 $a    $b    "abc" 'def'
161 .
162 no warnings 'deprecated' ;
163 format STDOUT =
164 @<<<  @|||  @>>>  @>>>
165 $a    $b    "abc" 'def'
166 .
167 EXPECT
168 Use of comma-less variable list is deprecated at - line 5.
169 Use of comma-less variable list is deprecated at - line 5.
170 Use of comma-less variable list is deprecated at - line 5.
171 ########
172 # toke.c
173 use warnings 'deprecated' ;
174 $a = <<;
175
176 no warnings 'deprecated' ;
177 $a = <<;
178
179 EXPECT
180 Use of bare << to mean <<"" is deprecated at - line 3.
181 ########
182 # toke.c
183 use warnings 'syntax' ;
184 s/(abc)/\1/;
185 no warnings 'syntax' ;
186 s/(abc)/\1/;
187 EXPECT
188 \1 better written as $1 at - line 3.
189 ########
190 # toke.c
191 use warnings 'semicolon' ;
192 $a = 1
193 &time ;
194 no warnings 'semicolon' ;
195 $a = 1
196 &time ;
197 EXPECT
198 Semicolon seems to be missing at - line 3.
199 ########
200 # toke.c
201 BEGIN {
202     # Scalars leaked: due to syntax errors
203     $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
204 }
205 use warnings 'syntax' ;
206 my $a =+ 2 ;
207 $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 EXPECT
217 Reversed += operator at - line 7.
218 Reversed -= operator at - line 8.
219 Reversed *= operator at - line 9.
220 Reversed %= operator at - line 10.
221 Reversed &= operator at - line 11.
222 Reversed .= operator at - line 12.
223 syntax error at - line 12, near "=."
224 Reversed ^= operator at - line 13.
225 syntax error at - line 13, near "=^"
226 Reversed |= operator at - line 14.
227 syntax error at - line 14, near "=|"
228 Reversed <= operator at - line 15.
229 Unterminated <> operator at - line 15.
230 ########
231 # toke.c
232 BEGIN {
233     # Scalars leaked: due to syntax errors
234     $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
235 }
236 no warnings 'syntax' ;
237 my $a =+ 2 ;
238 $a =- 2 ;
239 $a =* 2 ;
240 $a =% 2 ;
241 $a =& 2 ;
242 $a =. 2 ;
243 $a =^ 2 ;
244 $a =| 2 ;
245 $a =< 2 ;
246 $a =/ 2 ;
247 EXPECT
248 syntax error at - line 12, near "=."
249 syntax error at - line 13, near "=^"
250 syntax error at - line 14, near "=|"
251 Unterminated <> operator at - line 15.
252 ########
253 # toke.c
254 use warnings 'syntax' ;
255 my $a = $a[1,2] ;
256 no warnings 'syntax' ;
257 my $a = $a[1,2] ;
258 EXPECT
259 Multidimensional syntax $a[1,2] not supported at - line 3.
260 ########
261 # toke.c
262 use warnings 'syntax' ;
263 sub fred {} ; $SIG{TERM} = fred;
264 no warnings 'syntax' ;
265 $SIG{TERM} = fred;
266 EXPECT
267 You need to quote "fred" at - line 3.
268 ########
269 # toke.c
270 use warnings 'syntax' ;
271 @a[3] = 2;
272 @a{3} = 2;
273 no warnings 'syntax' ;
274 @a[3] = 2;
275 @a{3} = 2;
276 EXPECT
277 Scalar value @a[3] better written as $a[3] at - line 3.
278 Scalar value @a{3} better written as $a{3} at - line 4.
279 ########
280 # toke.c
281 use warnings 'syntax' ;
282 $_ = "ab" ; 
283 s/(ab)/\1/e;
284 no warnings 'syntax' ;
285 $_ = "ab" ; 
286 s/(ab)/\1/e;
287 EXPECT
288 Can't use \1 to mean $1 in expression at - line 4.
289 ########
290 # toke.c
291 use warnings 'reserved' ;
292 $a = abc;
293 no warnings 'reserved' ;
294 $a = abc;
295 EXPECT
296 Unquoted string "abc" may clash with future reserved word at - line 3.
297 ########
298 # toke.c
299 use warnings 'chmod' ;
300 chmod 3;
301 no warnings 'chmod' ;
302 chmod 3;
303 EXPECT
304 chmod() mode argument is missing initial 0 at - line 3.
305 ########
306 # toke.c
307 use warnings 'qw' ;
308 @a = qw(a, b, c) ;
309 no warnings 'qw' ;
310 @a = qw(a, b, c) ;
311 EXPECT
312 Possible attempt to separate words with commas at - line 3.
313 ########
314 # toke.c
315 use warnings 'qw' ;
316 @a = qw(a b #) ;
317 no warnings 'qw' ;
318 @a = qw(a b #) ;
319 EXPECT
320 Possible attempt to put comments in qw() list at - line 3.
321 ########
322 # toke.c
323 use warnings 'umask' ;
324 umask 3;
325 no warnings 'umask' ;
326 umask 3;
327 EXPECT
328 umask: argument is missing initial 0 at - line 3.
329 ########
330 # toke.c
331 use warnings 'syntax' ;
332 print ("")
333 EXPECT
334 print (...) interpreted as function at - line 3.
335 ########
336 # toke.c
337 no warnings 'syntax' ;
338 print ("")
339 EXPECT
340
341 ########
342 # toke.c
343 use warnings 'syntax' ;
344 printf ("")
345 EXPECT
346 printf (...) interpreted as function at - line 3.
347 ########
348 # toke.c
349 no warnings 'syntax' ;
350 printf ("")
351 EXPECT
352
353 ########
354 # toke.c
355 use warnings 'syntax' ;
356 sort ("")
357 EXPECT
358 sort (...) interpreted as function at - line 3.
359 ########
360 # toke.c
361 no warnings 'syntax' ;
362 sort ("")
363 EXPECT
364
365 ########
366 # toke.c
367 use warnings 'ambiguous' ;
368 $a = ${time[2]};
369 no warnings 'ambiguous' ;
370 $a = ${time[2]};
371 EXPECT
372 Ambiguous use of ${time[...]} resolved to $time[...] at - line 3.
373 ########
374 # toke.c
375 use warnings 'ambiguous' ;
376 $a = ${time{2}};
377 EXPECT
378 Ambiguous use of ${time{...}} resolved to $time{...} at - line 3.
379 ########
380 # toke.c
381 no warnings 'ambiguous' ;
382 $a = ${time{2}};
383 EXPECT
384
385 ########
386 # toke.c
387 use warnings 'ambiguous' ;
388 $a = ${time} ;
389 no warnings 'ambiguous' ;
390 $a = ${time} ;
391 EXPECT
392 Ambiguous use of ${time} resolved to $time at - line 3.
393 ########
394 # toke.c
395 use warnings 'ambiguous' ;
396 sub fred {}
397 $a = ${fred} ;
398 no warnings 'ambiguous' ;
399 $a = ${fred} ;
400 EXPECT
401 Ambiguous use of ${fred} resolved to $fred at - line 4.
402 ########
403 # toke.c
404 use warnings 'syntax' ;
405 $a = 1_2;
406 $a = 1_2345_6;
407 no warnings 'syntax' ;
408 $a = 1_2;
409 $a = 1_2345_6;
410 EXPECT
411 Misplaced _ in number at - line 3.
412 Misplaced _ in number at - line 4.
413 Misplaced _ in number at - line 4.
414 ########
415 # toke.c
416 use warnings 'bareword' ;
417 #line 25 "bar"
418 $a = FRED:: ;
419 no warnings 'bareword' ;
420 #line 25 "bar"
421 $a = FRED:: ;
422 EXPECT
423 Bareword "FRED::" refers to nonexistent package at bar line 25.
424 ########
425 # toke.c
426 use warnings 'ambiguous' ;
427 sub time {}
428 my $a = time() ;
429 no warnings 'ambiguous' ;
430 my $b = time() ;
431 EXPECT
432 Ambiguous call resolved as CORE::time(), qualify as such or use & at - line 4.
433 ########
434 # toke.c
435 use warnings ;
436 eval <<'EOE';
437 {
438 #line 30 "foo"
439   $_ = " \x{123} " ;
440 }
441 EOE
442 EXPECT
443
444 ########
445 # toke.c
446 my $a = rand + 4 ;
447 EXPECT
448 Warning: Use of "rand" without parens is ambiguous at - line 2.
449 ########
450 # toke.c
451 $^W = 0 ;
452 my $a = rand + 4 ;
453 {
454     no warnings 'ambiguous' ;
455     $a = rand + 4 ;
456     use warnings 'ambiguous' ;
457     $a = rand + 4 ;
458 }
459 $a = rand + 4 ;
460 EXPECT
461 Warning: Use of "rand" without parens is ambiguous at - line 3.
462 Warning: Use of "rand" without parens is ambiguous at - line 8.
463 Warning: Use of "rand" without parens is ambiguous at - line 10.
464 ########
465 # toke.c
466 sub fred {};
467 -fred ;
468 EXPECT
469 Ambiguous use of -fred resolved as -&fred() at - line 3.
470 ########
471 # toke.c
472 $^W = 0 ;
473 sub fred {} ;
474 -fred ;
475 {
476     no warnings 'ambiguous' ;
477     -fred ;
478     use warnings 'ambiguous' ;
479     -fred ;
480 }
481 -fred ;
482 EXPECT
483 Ambiguous use of -fred resolved as -&fred() at - line 4.
484 Ambiguous use of -fred resolved as -&fred() at - line 9.
485 Ambiguous use of -fred resolved as -&fred() at - line 11.
486 ########
487 # toke.c
488 open FOO || time;
489 EXPECT
490 Precedence problem: open FOO should be open(FOO) at - line 2.
491 ########
492 # toke.c
493 $^W = 0 ;
494 open FOO || time;
495 {
496     no warnings 'precedence' ;
497     open FOO || time;
498     use warnings 'precedence' ;
499     open FOO || time;
500 }
501 open FOO || time;
502 EXPECT
503 Precedence problem: open FOO should be open(FOO) at - line 3.
504 Precedence problem: open FOO should be open(FOO) at - line 8.
505 Precedence problem: open FOO should be open(FOO) at - line 10.
506 ########
507 # toke.c
508 $^W = 0 ;
509 *foo *foo ;
510 {
511     no warnings 'ambiguous' ;
512     *foo *foo ;
513     use warnings 'ambiguous' ;
514     *foo *foo ;
515 }
516 *foo *foo ;
517 EXPECT
518 Operator or semicolon missing before *foo at - line 3.
519 Ambiguous use of * resolved as operator * at - line 3.
520 Operator or semicolon missing before *foo at - line 8.
521 Ambiguous use of * resolved as operator * at - line 8.
522 Operator or semicolon missing before *foo at - line 10.
523 Ambiguous use of * resolved as operator * at - line 10.
524 ########
525 # toke.c
526 use warnings 'misc' ;
527 my $a = "\m" ;
528 no warnings 'misc' ;
529 $a = "\m" ;
530 EXPECT
531 Unrecognized escape \m passed through at - line 3.
532 ########
533 # toke.c
534 use warnings 'portable' ;
535 my $a =  0b011111111111111111111111111111110 ;
536    $a =  0b011111111111111111111111111111111 ;
537    $a =  0b111111111111111111111111111111111 ;
538    $a =  0x0fffffffe ;
539    $a =  0x0ffffffff ;
540    $a =  0x1ffffffff ;
541    $a =  0037777777776 ;
542    $a =  0037777777777 ;
543    $a =  0047777777777 ;
544 no warnings 'portable' ;
545    $a =  0b011111111111111111111111111111110 ;
546    $a =  0b011111111111111111111111111111111 ;
547    $a =  0b111111111111111111111111111111111 ;
548    $a =  0x0fffffffe ;
549    $a =  0x0ffffffff ;
550    $a =  0x1ffffffff ;
551    $a =  0037777777776 ;
552    $a =  0037777777777 ;
553    $a =  0047777777777 ;
554 EXPECT
555 Binary number > 0b11111111111111111111111111111111 non-portable at - line 5.
556 Hexadecimal number > 0xffffffff non-portable at - line 8.
557 Octal number > 037777777777 non-portable at - line 11.
558 ########
559 # toke.c
560 use warnings 'overflow' ;
561 my $a =  0b011111111111111111111111111111110 ;
562    $a =  0b011111111111111111111111111111111 ;
563    $a =  0b10000000000000000000000000000000000000000000000000000000000000000 ;
564    $a =  0x0fffffffe ;
565    $a =  0x0ffffffff ;
566    $a =  0x10000000000000000 ;
567    $a =  0037777777776 ;
568    $a =  0037777777777 ;
569    $a =  002000000000000000000000;
570 no warnings 'overflow' ;
571    $a =  0b011111111111111111111111111111110 ;
572    $a =  0b011111111111111111111111111111111 ;
573    $a =  0b10000000000000000000000000000000000000000000000000000000000000000 ;
574    $a =  0x0fffffffe ;
575    $a =  0x0ffffffff ;
576    $a =  0x10000000000000000 ;
577    $a =  0037777777776 ;
578    $a =  0037777777777 ;
579    $a =  002000000000000000000000;
580 EXPECT
581 Integer overflow in binary number at - line 5.
582 Integer overflow in hexadecimal number at - line 8.
583 Integer overflow in octal number at - line 11.