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