1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
|
op.c AOK
Use of my $_ is experimental
my $_ ;
Found = in conditional, should be ==
1 if $a = 1 ;
Scalar value %.*s better written as $%.*s"
@a[3] = 2;
@a{3} = 2;
Useless use of time in void context
Useless use of a variable in void context
Useless use of a constant in void context
time ;
$a ;
"abc"
Useless use of sort in scalar context
my $x = sort (2,1,3);
Applying %s to %s will act on scalar(%s)
my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
@a =~ /abc/ ;
@a =~ s/a/b/ ;
@a =~ tr/a/b/ ;
@$b =~ /abc/ ;
@$b =~ s/a/b/ ;
@$b =~ tr/a/b/ ;
%a =~ /abc/ ;
%a =~ s/a/b/ ;
%a =~ tr/a/b/ ;
%$c =~ /abc/ ;
%$c =~ s/a/b/ ;
%$c =~ tr/a/b/ ;
Parentheses missing around "my" list at -e line 1.
my $a, $b = (1,2);
Parentheses missing around "local" list at -e line 1.
local $a, $b = (1,2);
Bareword found in conditional at -e line 1.
use warnings 'bareword'; my $x = print(ABC || 1);
Value of %s may be \"0\"; use \"defined\"
$x = 1 if $x = <FH> ;
$x = 1 while $x = <FH> ;
Subroutine fred redefined at -e line 1.
sub fred{1;} sub fred{1;}
Constant subroutine %s redefined
sub fred() {1;} sub fred() {1;}
Format FRED redefined at /tmp/x line 5.
format FRED =
.
format FRED =
.
Array @%s missing the @ in argument %d of %s()
push fred ;
Hash %%%s missing the %% in argument %d of %s()
keys joe ;
Statement unlikely to be reached
(Maybe you meant system() when you said exec()?
exec "true" ; my $a
defined(@array) is deprecated
(Maybe you should just omit the defined()?)
my @a ; defined @a ;
defined (@a = (1,2,3)) ;
defined(%hash) is deprecated
(Maybe you should just omit the defined()?)
my %h ; defined %h ;
"my %s" used in sort comparison
$[ used in comparison (did you mean $] ?)
length() used on @array (did you mean "scalar(@array)"?)
length() used on %hash (did you mean "scalar(keys %hash)"?)
/---/ should probably be written as "---"
join(/---/, @foo);
%s() called too early to check prototype [Perl_peep]
fred() ; sub fred ($$) {}
Package '%s' not found (did you use the incorrect case?)
Use of /g modifier is meaningless in split
Possible precedence problem on bitwise %c operator [Perl_ck_bitop]
Mandatory Warnings
------------------
Prototype mismatch: [cv_ckproto]
sub fred() ;
sub fred($) {}
oops: oopsAV [oopsAV] TODO
oops: oopsHV [oopsHV] TODO
__END__
# op.c
use warnings 'experimental::lexical_topic' ;
my $_;
CORE::state $_;
no warnings 'experimental::lexical_topic' ;
my $_;
CORE::state $_;
EXPECT
Use of my $_ is experimental at - line 3.
Use of state $_ is experimental at - line 4.
########
# op.c
use warnings 'syntax' ;
1 if $a = 1 ;
1 if $a
= 1 ;
no warnings 'syntax' ;
1 if $a = 1 ;
1 if $a
= 1 ;
EXPECT
Found = in conditional, should be == at - line 3.
Found = in conditional, should be == at - line 4.
########
# op.c
use warnings 'syntax' ;
use constant foo => 1;
1 if $a = foo ;
no warnings 'syntax' ;
1 if $a = foo ;
EXPECT
########
# op.c
use warnings 'syntax' ;
@a[3];
@a{3};
@a["]"];
@a{"]"};
@a["}"];
@a{"}"};
@a{$_};
@a{--$_};
@a[$_];
@a[--$_];
no warnings 'syntax' ;
@a[3];
@a{3};
EXPECT
Scalar value @a[3] better written as $a[3] at - line 3.
Scalar value @a{3} better written as $a{3} at - line 4.
Scalar value @a["]"] better written as $a["]"] at - line 5.
Scalar value @a{"]"} better written as $a{"]"} at - line 6.
Scalar value @a["}"] better written as $a["}"] at - line 7.
Scalar value @a{"}"} better written as $a{"}"} at - line 8.
Scalar value @a{...} better written as $a{...} at - line 9.
Scalar value @a{...} better written as $a{...} at - line 10.
Scalar value @a[...] better written as $a[...] at - line 11.
Scalar value @a[...] better written as $a[...] at - line 12.
########
# op.c
use utf8;
use open qw( :utf8 :std );
use warnings 'syntax' ;
@à[3];
@à{3};
no warnings 'syntax' ;
@à[3];
@à{3};
EXPECT
Scalar value @à[3] better written as $à[3] at - line 5.
Scalar value @à{3} better written as $à{3} at - line 6.
########
# op.c
use utf8;
use open qw( :utf8 :std );
use warnings 'syntax' ;
@ぁ[3];
@ぁ{3};
no warnings 'syntax' ;
@ぁ[3];
@ぁ{3};
EXPECT
Scalar value @ぁ[3] better written as $ぁ[3] at - line 5.
Scalar value @ぁ{3} better written as $ぁ{3} at - line 6.
########
# op.c
# "Scalar value better written as" false positives
# [perl #28380] and [perl #114024]
use warnings 'syntax';
# hashes
@h{qw"a b c"} = 1..3;
@h{qw'a b c'} = 1..3;
@h{qw$a b c$} = 1..3;
@h{qw-a b c-} = 1..3;
@h{qw#a b c#} = 1..3;
@h{ qw#a b c#} = 1..3;
@h{ qw#a b c#} = 1..3; # tab before qw
@h{qw "a"};
@h{ qw "a"};
@h{ qw "a"};
sub foo() { qw/abc def ghi/ }
@X{+foo} = ( 1 .. 3 );
$_ = "abc"; @X{split ""} = ( 1 .. 3 );
my @s = @f{"}", "a"};
my @s = @f{"]", "a"};
@a{$],0};
@_{0} = /(.*)/;
@h{m "$re"};
@h{qx ""} if 0;
@h{glob ""};
@h{readline ""};
@h{m ""};
use constant phoo => 1..3;
@h{+phoo}; # rv2av
{
no warnings 'deprecated';
@h{each H};
@h{values H};
@h{keys H};
}
@h{sort foo};
@h{reverse foo};
@h{caller 0};
@h{lstat ""};
@h{stat ""};
@h{readdir ""};
@h{system ""} if 0;
@h{+times} if 0;
@h{localtime 0};
@h{gmtime 0};
@h{eval ""};
@h{each $foo} if 0;
@h{keys $foo} if 0;
@h{values $foo} if 0;
# arrays
@h[qw"a b c"] = 1..3;
@h[qw'a b c'] = 1..3;
@h[qw$a b c$] = 1..3;
@h[qw-a b c-] = 1..3;
@h[qw#a b c#] = 1..3;
@h[ qw#a b c#] = 1..3;
@h[ qw#a b c#] = 1..3; # tab before qw
@h[qw "a"];
@h[ qw "a"];
@h[ qw "a"];
sub foo() { qw/abc def ghi/ }
@X[+foo] = ( 1 .. 3 );
$_ = "abc"; @X[split ""] = ( 1 .. 3 );
my @s = @f["}", "a"];
my @s = @f["]", "a"];
@a[$],0];
@_[0] = /(.*)/;
@h[m "$re"];
@h[qx ""] if 0;
@h[glob ""];
@h[readline ""];
@h[m ""];
use constant phoo => 1..3;
@h[+phoo]; # rv2av
{
no warnings 'deprecated';
@h[each H];
@h[values H];
@h[keys H];
}
@h[sort foo];
@h[reverse foo];
@h[caller 0];
@h[lstat ""];
@h[stat ""];
@h[readdir ""];
@h[system ""] if 0;
@h[+times] if 0;
@h[localtime 0];
@h[gmtime 0];
@h[eval ""];
@h[each $foo] if 0;
@h[keys $foo] if 0;
@h[values $foo] if 0;
EXPECT
########
# op.c
# "Scalar value better written as" should not trigger for syntax errors
use warnings 'syntax';
@a[]
EXPECT
syntax error at - line 4, near "[]"
Execution of - aborted due to compilation errors.
########
# op.c
my (@foo, %foo);
%main::foo->{"bar"};
%foo->{"bar"};
@main::foo->[23];
@foo->[23];
$main::foo = {}; %$main::foo->{"bar"};
$foo = {}; %$foo->{"bar"};
$main::foo = []; @$main::foo->[34];
$foo = []; @$foo->[34];
no warnings 'deprecated';
%main::foo->{"bar"};
%foo->{"bar"};
@main::foo->[23];
@foo->[23];
$main::foo = {}; %$main::foo->{"bar"};
$foo = {}; %$foo->{"bar"};
$main::foo = []; @$main::foo->[34];
$foo = []; @$foo->[34];
EXPECT
Using a hash as a reference is deprecated at - line 3.
Using a hash as a reference is deprecated at - line 4.
Using an array as a reference is deprecated at - line 5.
Using an array as a reference is deprecated at - line 6.
Using a hash as a reference is deprecated at - line 7.
Using a hash as a reference is deprecated at - line 8.
Using an array as a reference is deprecated at - line 9.
Using an array as a reference is deprecated at - line 10.
########
# op.c
use warnings 'void' ; no warnings 'experimental::smartmatch'; close STDIN ;
#line 2
1 x 3 ; # OP_REPEAT (folded)
(1) x 3 ; # OP_REPEAT
# OP_GVSV
wantarray ; # OP_WANTARRAY
# OP_GV
# OP_PADSV
# OP_PADAV
# OP_PADHV
# OP_PADANY
# OP_AV2ARYLEN
ref ; # OP_REF
\@a ; # OP_REFGEN
\$a ; # OP_SREFGEN
defined $a ; # OP_DEFINED
hex $a ; # OP_HEX
oct $a ; # OP_OCT
length $a ; # OP_LENGTH
substr $a,1 ; # OP_SUBSTR
vec $a,1,2 ; # OP_VEC
index $a,1,2 ; # OP_INDEX
rindex $a,1,2 ; # OP_RINDEX
sprintf $a ; # OP_SPRINTF
$a[0] ; # OP_AELEM
# OP_AELEMFAST
@a[0] ; # OP_ASLICE
#values %a ; # OP_VALUES
#keys %a ; # OP_KEYS
$a{0} ; # OP_HELEM
@a{0} ; # OP_HSLICE
unpack "a", "a" ; # OP_UNPACK
pack $a,"" ; # OP_PACK
join "" ; # OP_JOIN
(@a)[0,1] ; # OP_LSLICE
# OP_ANONLIST
# OP_ANONHASH
sort(1,2) ; # OP_SORT
reverse(1,2) ; # OP_REVERSE
# OP_RANGE
# OP_FLIP
(1 ..2) ; # OP_FLOP
caller ; # OP_CALLER
fileno STDIN ; # OP_FILENO
eof STDIN ; # OP_EOF
tell STDIN ; # OP_TELL
readlink 1; # OP_READLINK
time ; # OP_TIME
localtime ; # OP_LOCALTIME
gmtime ; # OP_GMTIME
eval { getgrnam 1 }; # OP_GGRNAM
eval { getgrgid 1 }; # OP_GGRGID
eval { getpwnam 1 }; # OP_GPWNAM
eval { getpwuid 1 }; # OP_GPWUID
prototype "foo"; # OP_PROTOTYPE
$a ~~ $b; # OP_SMARTMATCH
$a <=> $b; # OP_NCMP
"dsatrewq";
"diatrewq";
"igatrewq";
use 5.015;
__SUB__ # OP_RUNCV
EXPECT
Useless use of a constant ("111") in void context at - line 2.
Useless use of repeat (x) in void context at - line 3.
Useless use of wantarray in void context at - line 5.
Useless use of reference-type operator in void context at - line 12.
Useless use of reference constructor in void context at - line 13.
Useless use of single ref constructor in void context at - line 14.
Useless use of defined operator in void context at - line 15.
Useless use of hex in void context at - line 16.
Useless use of oct in void context at - line 17.
Useless use of length in void context at - line 18.
Useless use of substr in void context at - line 19.
Useless use of vec in void context at - line 20.
Useless use of index in void context at - line 21.
Useless use of rindex in void context at - line 22.
Useless use of sprintf in void context at - line 23.
Useless use of array element in void context at - line 24.
Useless use of array slice in void context at - line 26.
Useless use of hash element in void context at - line 29.
Useless use of hash slice in void context at - line 30.
Useless use of unpack in void context at - line 31.
Useless use of pack in void context at - line 32.
Useless use of join or string in void context at - line 33.
Useless use of list slice in void context at - line 34.
Useless use of sort in void context at - line 37.
Useless use of reverse in void context at - line 38.
Useless use of range (or flop) in void context at - line 41.
Useless use of caller in void context at - line 42.
Useless use of fileno in void context at - line 43.
Useless use of eof in void context at - line 44.
Useless use of tell in void context at - line 45.
Useless use of readlink in void context at - line 46.
Useless use of time in void context at - line 47.
Useless use of localtime in void context at - line 48.
Useless use of gmtime in void context at - line 49.
Useless use of getgrnam in void context at - line 50.
Useless use of getgrgid in void context at - line 51.
Useless use of getpwnam in void context at - line 52.
Useless use of getpwuid in void context at - line 53.
Useless use of subroutine prototype in void context at - line 54.
Useless use of smart match in void context at - line 55.
Useless use of numeric comparison (<=>) in void context at - line 56.
Useless use of a constant ("dsatrewq") in void context at - line 57.
Useless use of a constant ("diatrewq") in void context at - line 58.
Useless use of a constant ("igatrewq") in void context at - line 59.
Useless use of __SUB__ in void context at - line 61.
########
# op.c
use warnings 'void' ; close STDIN ;
my $x = sort (2,1,3);
no warnings 'void' ;
$x = sort (2,1,3);
EXPECT
Useless use of sort in scalar context at - line 3.
########
# op.c
no warnings 'void' ; close STDIN ;
1 x 3 ; # OP_REPEAT
# OP_GVSV
wantarray ; # OP_WANTARRAY
# OP_GV
# OP_PADSV
# OP_PADAV
# OP_PADHV
# OP_PADANY
# OP_AV2ARYLEN
ref ; # OP_REF
\@a ; # OP_REFGEN
\$a ; # OP_SREFGEN
defined $a ; # OP_DEFINED
hex $a ; # OP_HEX
oct $a ; # OP_OCT
length $a ; # OP_LENGTH
substr $a,1 ; # OP_SUBSTR
vec $a,1,2 ; # OP_VEC
index $a,1,2 ; # OP_INDEX
rindex $a,1,2 ; # OP_RINDEX
sprintf $a ; # OP_SPRINTF
$a[0] ; # OP_AELEM
# OP_AELEMFAST
@a[0] ; # OP_ASLICE
#values %a ; # OP_VALUES
#keys %a ; # OP_KEYS
$a{0} ; # OP_HELEM
@a{0} ; # OP_HSLICE
unpack "a", "a" ; # OP_UNPACK
pack $a,"" ; # OP_PACK
join "" ; # OP_JOIN
(@a)[0,1] ; # OP_LSLICE
# OP_ANONLIST
# OP_ANONHASH
sort(1,2) ; # OP_SORT
reverse(1,2) ; # OP_REVERSE
# OP_RANGE
# OP_FLIP
(1 ..2) ; # OP_FLOP
caller ; # OP_CALLER
fileno STDIN ; # OP_FILENO
eof STDIN ; # OP_EOF
tell STDIN ; # OP_TELL
readlink 1; # OP_READLINK
time ; # OP_TIME
localtime ; # OP_LOCALTIME
gmtime ; # OP_GMTIME
eval { getgrnam 1 }; # OP_GGRNAM
eval { getgrgid 1 }; # OP_GGRGID
eval { getpwnam 1 }; # OP_GPWNAM
eval { getpwuid 1 }; # OP_GPWUID
prototype "foo"; # OP_PROTOTYPE
EXPECT
########
# op.c
use warnings 'void' ;
for (@{[0]}) { "$_" } # check warning isn't duplicated
no warnings 'void' ;
for (@{[0]}) { "$_" } # check warning isn't duplicated
EXPECT
Useless use of string in void context at - line 3.
########
# op.c
use warnings 'void' ;
use Config ;
BEGIN {
if ( ! $Config{d_telldir}) {
print <<EOM ;
SKIPPED
# telldir not present
EOM
exit
}
}
telldir 1 ; # OP_TELLDIR
no warnings 'void' ;
telldir 1 ; # OP_TELLDIR
EXPECT
Useless use of telldir in void context at - line 13.
########
# op.c
use warnings 'void' ;
use Config ;
BEGIN {
if ( ! $Config{d_getppid}) {
print <<EOM ;
SKIPPED
# getppid not present
EOM
exit
}
}
getppid ; # OP_GETPPID
no warnings 'void' ;
getppid ; # OP_GETPPID
EXPECT
Useless use of getppid in void context at - line 13.
########
# op.c
use warnings 'void' ;
use Config ;
BEGIN {
if ( ! $Config{d_getpgrp}) {
print <<EOM ;
SKIPPED
# getpgrp not present
EOM
exit
}
}
getpgrp ; # OP_GETPGRP
no warnings 'void' ;
getpgrp ; # OP_GETPGRP
EXPECT
Useless use of getpgrp in void context at - line 13.
########
# op.c
use warnings 'void' ;
use Config ;
BEGIN {
if ( ! $Config{d_times}) {
print <<EOM ;
SKIPPED
# times not present
EOM
exit
}
}
times ; # OP_TMS
no warnings 'void' ;
times ; # OP_TMS
EXPECT
Useless use of times in void context at - line 13.
########
# op.c
use warnings 'void' ;
use Config ;
BEGIN {
if ( ! $Config{d_getprior} or $^O eq 'os2') { # Locks before fixpak22
print <<EOM ;
SKIPPED
# getpriority not present
EOM
exit
}
}
getpriority 1,2; # OP_GETPRIORITY
no warnings 'void' ;
getpriority 1,2; # OP_GETPRIORITY
EXPECT
Useless use of getpriority in void context at - line 13.
########
# op.c
use warnings 'void' ;
use Config ;
BEGIN {
if ( ! $Config{d_getlogin}) {
print <<EOM ;
SKIPPED
# getlogin not present
EOM
exit
}
}
getlogin ; # OP_GETLOGIN
no warnings 'void' ;
getlogin ; # OP_GETLOGIN
EXPECT
Useless use of getlogin in void context at - line 13.
########
# op.c
use warnings 'void' ;
use Config ; BEGIN {
if ( ! $Config{d_socket}) {
print <<EOM ;
SKIPPED
# getsockname not present
# getpeername not present
# gethostbyname not present
# gethostbyaddr not present
# gethostent not present
# getnetbyname not present
# getnetbyaddr not present
# getnetent not present
# getprotobyname not present
# getprotobynumber not present
# getprotoent not present
# getservbyname not present
# getservbyport not present
# getservent not present
EOM
exit
} }
getsockname STDIN ; # OP_GETSOCKNAME
getpeername STDIN ; # OP_GETPEERNAME
gethostbyname 1 ; # OP_GHBYNAME
gethostbyaddr 1,2; # OP_GHBYADDR
gethostent ; # OP_GHOSTENT
getnetbyname 1 ; # OP_GNBYNAME
getnetbyaddr 1,2 ; # OP_GNBYADDR
getnetent ; # OP_GNETENT
getprotobyname 1; # OP_GPBYNAME
getprotobynumber 1; # OP_GPBYNUMBER
getprotoent ; # OP_GPROTOENT
getservbyname 1,2; # OP_GSBYNAME
getservbyport 1,2; # OP_GSBYPORT
getservent ; # OP_GSERVENT
no warnings 'void' ;
getsockname STDIN ; # OP_GETSOCKNAME
getpeername STDIN ; # OP_GETPEERNAME
gethostbyname 1 ; # OP_GHBYNAME
gethostbyaddr 1,2; # OP_GHBYADDR
gethostent ; # OP_GHOSTENT
getnetbyname 1 ; # OP_GNBYNAME
getnetbyaddr 1,2 ; # OP_GNBYADDR
getnetent ; # OP_GNETENT
getprotobyname 1; # OP_GPBYNAME
getprotobynumber 1; # OP_GPBYNUMBER
getprotoent ; # OP_GPROTOENT
getservbyname 1,2; # OP_GSBYNAME
getservbyport 1,2; # OP_GSBYPORT
getservent ; # OP_GSERVENT
INIT {
# some functions may not be there, so we exit without running
exit;
}
EXPECT
Useless use of getsockname in void context at - line 24.
Useless use of getpeername in void context at - line 25.
Useless use of gethostbyname in void context at - line 26.
Useless use of gethostbyaddr in void context at - line 27.
Useless use of gethostent in void context at - line 28.
Useless use of getnetbyname in void context at - line 29.
Useless use of getnetbyaddr in void context at - line 30.
Useless use of getnetent in void context at - line 31.
Useless use of getprotobyname in void context at - line 32.
Useless use of getprotobynumber in void context at - line 33.
Useless use of getprotoent in void context at - line 34.
Useless use of getservbyname in void context at - line 35.
Useless use of getservbyport in void context at - line 36.
Useless use of getservent in void context at - line 37.
########
# op.c
use warnings 'void' ;
*a ; # OP_RV2GV
$a ; # OP_RV2SV
@a ; # OP_RV2AV
%a ; # OP_RV2HV
no warnings 'void' ;
*a ; # OP_RV2GV
$a ; # OP_RV2SV
@a ; # OP_RV2AV
%a ; # OP_RV2HV
EXPECT
Useless use of a variable in void context at - line 3.
Useless use of a variable in void context at - line 4.
Useless use of a variable in void context at - line 5.
Useless use of a variable in void context at - line 6.
########
# op.c
use warnings 'void' ;
"abc"; # OP_CONST
7 ; # OP_CONST
"x" . "y"; # optimized to OP_CONST
2 + 2; # optimized to OP_CONST
use constant U => undef;
U;
qq/" \n/;
5 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT
print "boo\n" if U; # test OPpCONST_SHORTCIRCUIT
if($foo){}elsif(""){} # test OPpCONST_SHORTCIRCUIT
no warnings 'void' ;
"abc"; # OP_CONST
7 ; # OP_CONST
"x" . "y"; # optimized to OP_CONST
2 + 2; # optimized to OP_CONST
EXPECT
Useless use of a constant ("abc") in void context at - line 3.
Useless use of a constant (7) in void context at - line 4.
Useless use of a constant ("xy") in void context at - line 5.
Useless use of a constant (4) in void context at - line 6.
Useless use of a constant (undef) in void context at - line 8.
Useless use of a constant ("\"\t\n") in void context at - line 9.
########
# op.c
use utf8;
use open qw( :utf8 :std );
use warnings 'void' ;
"àḆc"; # OP_CONST
"Ẋ" . "ƴ"; # optimized to OP_CONST
FOO; # Bareword optimized to OP_CONST
use constant ů => undef;
ů;
5 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT
print "boo\n" if ů; # test OPpCONST_SHORTCIRCUIT
no warnings 'void' ;
"àḆc"; # OP_CONST
"Ẋ" . "ƴ"; # optimized to OP_CONST
EXPECT
Useless use of a constant ("\340\x{1e06}c") in void context at - line 5.
Useless use of a constant ("\x{1e8a}\x{1b4}") in void context at - line 6.
Useless use of a constant ("\x{ff26}\x{ff2f}\x{ff2f}") in void context at - line 7.
Useless use of a constant (undef) in void context at - line 9.
########
# op.c
#
use warnings 'misc' ;
my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;my $d = 'test';
@a =~ /abc/ ;
@a2 =~ s/a/b/ ;
@a3 =~ tr/a/b/ ;
@$b =~ /abc/ ;
@$b =~ s/a/b/ ;
@$b =~ tr/a/b/ ;
%a =~ /abc/ ;
%a2 =~ s/a/b/ ;
%a3 =~ tr/a/b/ ;
%$c =~ /abc/ ;
%$c =~ s/a/b/ ;
%$c =~ tr/a/b/ ;
$d =~ tr/a/b/d ;
$d2 =~ tr/a/bc/;
$d3 =~ tr//b/c;
{
no warnings 'misc' ;
my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; my $d = 'test';
@a =~ /abc/ ;
@a =~ s/a/b/ ;
@a =~ tr/a/b/ ;
@$b =~ /abc/ ;
@$b =~ s/a/b/ ;
@$b =~ tr/a/b/ ;
%a =~ /abc/ ;
%a =~ s/a/b/ ;
%a =~ tr/a/b/ ;
%$c =~ /abc/ ;
%$c =~ s/a/b/ ;
%$c =~ tr/a/b/ ;
$d =~ tr/a/b/d ;
$d =~ tr/a/bc/ ;
$d =~ tr//b/c;
}
EXPECT
Applying pattern match (m//) to @a will act on scalar(@a) at - line 5.
Applying substitution (s///) to @a2 will act on scalar(@a2) at - line 6.
Applying transliteration (tr///) to @a3 will act on scalar(@a3) at - line 7.
Applying pattern match (m//) to @array will act on scalar(@array) at - line 8.
Applying substitution (s///) to @array will act on scalar(@array) at - line 9.
Applying transliteration (tr///) to @array will act on scalar(@array) at - line 10.
Applying pattern match (m//) to %a will act on scalar(%a) at - line 11.
Applying substitution (s///) to %a2 will act on scalar(%a2) at - line 12.
Applying transliteration (tr///) to %a3 will act on scalar(%a3) at - line 13.
Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 14.
Applying substitution (s///) to %hash will act on scalar(%hash) at - line 15.
Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 16.
Useless use of /d modifier in transliteration operator at - line 17.
Replacement list is longer than search list at - line 18.
Can't modify array dereference in substitution (s///) at - line 6, near "s/a/b/ ;"
BEGIN not safe after errors--compilation aborted at - line 21.
########
# op.c
use warnings 'parenthesis' ;
my $a, $b = (1,2);
my @foo,%bar, $quux; # there's a TAB here
my $x, $y or print;
no warnings 'parenthesis' ;
my $c, $d = (1,2);
EXPECT
Parentheses missing around "my" list at - line 3.
Parentheses missing around "my" list at - line 4.
########
# op.c
use warnings 'parenthesis' ;
our $a, $b = (1,2);
no warnings 'parenthesis' ;
our $c, $d = (1,2);
EXPECT
Parentheses missing around "our" list at - line 3.
########
# op.c
use warnings 'parenthesis' ;
local $a, $b = (1,2);
local *f, *g;
no warnings 'parenthesis' ;
local $c, $d = (1,2);
EXPECT
Parentheses missing around "local" list at - line 3.
Parentheses missing around "local" list at - line 4.
########
# op.c
use warnings 'bareword' ;
print (ABC || 1) ;
no warnings 'bareword' ;
print (ABC || 1) ;
EXPECT
Bareword found in conditional at - line 3.
########
--FILE-- abc
--FILE--
# op.c
use warnings 'misc' ;
open FH, "<abc" ;
$x = 1 if $x = <FH> ;
$x = 1 if $x
= <FH> ;
no warnings 'misc' ;
$x = 1 if $x = <FH> ;
$x = 1 if $x
= <FH> ;
EXPECT
Value of <HANDLE> construct can be "0"; test with defined() at - line 4.
Value of <HANDLE> construct can be "0"; test with defined() at - line 5.
########
# op.c
use warnings 'misc' ;
opendir FH, "." ;
$x = 1 if $x = readdir FH ;
$x = 1 if $x
= readdir FH ;
no warnings 'misc' ;
$x = 1 if $x = readdir FH ;
$x = 1 if $x
= readdir FH ;
closedir FH ;
EXPECT
Value of readdir() operator can be "0"; test with defined() at - line 4.
Value of readdir() operator can be "0"; test with defined() at - line 5.
########
# op.c
use warnings 'misc' ;
$x = 1 if $x = <*> ;
$x = 1 if $x
= <*> ;
no warnings 'misc' ;
$x = 1 if $x = <*> ;
$x = 1 if $x
= <*> ;
EXPECT
Value of glob construct can be "0"; test with defined() at - line 3.
Value of glob construct can be "0"; test with defined() at - line 4.
########
# op.c
use warnings 'misc' ;
%a = (1,2,3,4) ;
$x = 1 if $x = each %a ;
no warnings 'misc' ;
$x = 1 if $x = each %a ;
EXPECT
Value of each() operator can be "0"; test with defined() at - line 4.
########
# op.c
use warnings 'misc' ;
$x = 1 while $x = <*> and 0 ;
no warnings 'misc' ;
$x = 1 while $x = <*> and 0 ;
EXPECT
Value of glob construct can be "0"; test with defined() at - line 3.
########
# op.c
use warnings 'misc' ;
opendir FH, "." ;
$x = 1 while $x = readdir FH and 0 ;
no warnings 'misc' ;
$x = 1 while $x = readdir FH and 0 ;
closedir FH ;
EXPECT
Value of readdir() operator can be "0"; test with defined() at - line 4.
########
# op.c
use warnings 'misc';
open FH, "<abc";
($_ = <FH>) // ($_ = 1);
opendir DH, ".";
%a = (1,2,3,4) ;
EXPECT
########
# op.c
use warnings 'redefine' ;
sub fred {}
sub fred {}
sub fred { # warning should be for this line
}
no warnings 'redefine' ;
sub fred {}
sub fred {
}
EXPECT
Subroutine fred redefined at - line 4.
Subroutine fred redefined at - line 5.
########
# op.c
use warnings 'redefine' ;
sub fred () { 1 }
sub fred () { 1 }
no warnings 'redefine' ;
sub fred () { 1 }
EXPECT
Constant subroutine fred redefined at - line 4.
########
# op.c
sub fred () { 1 }
sub fred () { 2 }
EXPECT
Constant subroutine fred redefined at - line 3.
########
# op.c
sub fred () { 1 }
*fred = sub () { 2 };
EXPECT
Constant subroutine main::fred redefined at - line 3.
########
# op.c
use feature "lexical_subs", "state";
my sub fred () { 1 }
sub fred { 2 };
my sub george { 1 }
sub george () { 2 } # should *not* produce redef warnings by default
state sub phred () { 1 }
sub phred { 2 };
state sub jorge { 1 }
sub jorge () { 2 } # should *not* produce redef warnings by default
EXPECT
The lexical_subs feature is experimental at - line 3.
Prototype mismatch: sub fred () vs none at - line 4.
Constant subroutine fred redefined at - line 4.
The lexical_subs feature is experimental at - line 5.
Prototype mismatch: sub george: none vs () at - line 6.
The lexical_subs feature is experimental at - line 7.
Prototype mismatch: sub phred () vs none at - line 8.
Constant subroutine phred redefined at - line 8.
The lexical_subs feature is experimental at - line 9.
Prototype mismatch: sub jorge: none vs () at - line 10.
########
# op.c
no warnings 'redefine' ;
sub fred () { 1 }
sub fred () { 2 }
EXPECT
########
# op.c
no warnings 'redefine' ;
sub fred () { 1 }
*fred = sub () { 2 };
EXPECT
########
# op.c
use warnings 'redefine' ;
format FRED =
.
format FRED =
.
no warnings 'redefine' ;
format FRED =
.
EXPECT
Format FRED redefined at - line 5.
########
# op.c
push FRED;
no warnings 'deprecated' ;
push FRED;
EXPECT
Array @FRED missing the @ in argument 1 of push() at - line 2.
########
# op.c
@a = keys FRED ;
no warnings 'deprecated' ;
@a = keys FRED ;
EXPECT
Hash %FRED missing the % in argument 1 of keys() at - line 2.
########
# op.c
use warnings 'exec' ;
exec "$^X -e 1" ;
my $a
EXPECT
Statement unlikely to be reached at - line 4.
(Maybe you meant system() when you said exec()?)
########
# op.c, no warning if exec isn't a statement.
use warnings 'exec' ;
$a || exec "$^X -e 1" ;
my $a
EXPECT
########
# op.c
defined(@a);
EXPECT
defined(@array) is deprecated at - line 2.
(Maybe you should just omit the defined()?)
########
# op.c
my @a; defined(@a);
EXPECT
defined(@array) is deprecated at - line 2.
(Maybe you should just omit the defined()?)
########
# op.c
defined(@a = (1,2,3));
EXPECT
defined(@array) is deprecated at - line 2.
(Maybe you should just omit the defined()?)
########
# op.c
defined(%h);
EXPECT
defined(%hash) is deprecated at - line 2.
(Maybe you should just omit the defined()?)
########
# op.c
my %h; defined(%h);
EXPECT
defined(%hash) is deprecated at - line 2.
(Maybe you should just omit the defined()?)
########
# op.c
no warnings 'exec' ;
exec "$^X -e 1" ;
my $a
EXPECT
########
# op.c
sub fred();
sub fred($) {}
use constant foo=>bar; sub foo(@);
use constant bav=>bar; sub bav(); # no warning
sub btu; sub btu();
EXPECT
Prototype mismatch: sub main::fred () vs ($) at - line 3.
Prototype mismatch: sub foo () vs (@) at - line 4.
Prototype mismatch: sub btu: none vs () at - line 6.
########
# op.c
use utf8;
use open qw( :utf8 :std );
sub frèd();
sub frèd($) {}
EXPECT
Prototype mismatch: sub main::frèd () vs ($) at - line 5.
########
# op.c
use utf8;
use open qw( :utf8 :std );
use warnings;
eval "sub fòò (@\$\0) {}";
EXPECT
Prototype after '@' for main::fòò : @$\0 at (eval 1) line 1.
Illegal character in prototype for main::fòò : @$\0 at (eval 1) line 1.
########
# op.c
use utf8;
use open qw( :utf8 :std );
use warnings;
eval "sub foo (@\0) {}";
EXPECT
Prototype after '@' for main::foo : @\0 at (eval 1) line 1.
Illegal character in prototype for main::foo : @\0 at (eval 1) line 1.
########
# op.c
use utf8;
use open qw( :utf8 :std );
use warnings;
BEGIN { $::{"foo"} = "\@\$\0L\351on" }
BEGIN { eval "sub foo (@\$\0L\x{c3}\x{a9}on) {}"; }
EXPECT
Prototype after '@' for main::foo : @$\x{0}L... at (eval 1) line 1.
Illegal character in prototype for main::foo : @$\x{0}L... at (eval 1) line 1.
########
# op.c
use utf8;
use open qw( :utf8 :std );
use warnings;
BEGIN { eval "sub foo (@\0) {}"; }
EXPECT
Prototype after '@' for main::foo : @\0 at (eval 1) line 1.
Illegal character in prototype for main::foo : @\0 at (eval 1) line 1.
########
# op.c
use warnings;
eval "sub foo (@\xAB) {}";
EXPECT
Prototype after '@' for main::foo : @\x{ab} at (eval 1) line 1.
Illegal character in prototype for main::foo : @\x{ab} at (eval 1) line 1.
########
# op.c
use utf8;
use open qw( :utf8 :std );
use warnings;
BEGIN { eval "sub foo (@\x{30cb}) {}"; }
EXPECT
Prototype after '@' for main::foo : @\x{30cb} at (eval 1) line 1.
Illegal character in prototype for main::foo : @\x{30cb} at (eval 1) line 1.
########
# op.c
use utf8;
use open qw( :utf8 :std );
use warnings;
BEGIN { $::{"foo"} = "\x{30cb}" }
BEGIN { eval "sub foo {}"; }
EXPECT
Prototype mismatch: sub main::foo (ニ) vs none at (eval 1) line 1.
########
# op.c
$^W = 0 ;
sub fred() ;
sub fred($) {}
{
no warnings 'prototype' ;
sub Fred() ;
sub Fred($) {}
use warnings 'prototype' ;
sub freD() ;
sub freD($) {}
}
sub FRED() ;
sub FRED($) {}
EXPECT
Prototype mismatch: sub main::fred () vs ($) at - line 4.
Prototype mismatch: sub main::freD () vs ($) at - line 11.
Prototype mismatch: sub main::FRED () vs ($) at - line 14.
########
# op.c [S_simplify_sort]
# [perl #86136]
my @tests = split /^/, '
sort {$a <=> $b} @a;
sort {$a cmp $b} @a;
{ use integer; sort {$a <=> $b} @a}
sort {$b <=> $a} @a;
sort {$b cmp $a} @a;
{ use integer; sort {$b <=> $a} @a}
';
for my $pragma ('use warnings "syntax";', '') {
for my $vars ('', 'my $a;', 'my $b;', 'my ($a,$b);') {
for my $inner_stmt ('', 'print;', 'func();') {
eval "#line " . ++$line . "01 -\n$pragma\n$vars"
. join "", map s/sort \{\K/$inner_stmt/r, @tests;
$@ and die;
}
}
}
sub func{}
use warnings 'syntax';
my $a;
# These used to be errors!
sort { ; } $a <=> $b;
sort { ; } $a, "<=>";
sort { ; } $a, $cmp;
sort $a, $b if $cmpany_name;
sort if $a + $cmp;
sort @t; $a + $cmp;
EXPECT
"my $a" used in sort comparison at - line 403.
"my $a" used in sort comparison at - line 404.
"my $a" used in sort comparison at - line 405.
"my $a" used in sort comparison at - line 406.
"my $a" used in sort comparison at - line 407.
"my $a" used in sort comparison at - line 408.
"my $a" used in sort comparison at - line 503.
"my $a" used in sort comparison at - line 504.
"my $a" used in sort comparison at - line 505.
"my $a" used in sort comparison at - line 506.
"my $a" used in sort comparison at - line 507.
"my $a" used in sort comparison at - line 508.
"my $a" used in sort comparison at - line 603.
"my $a" used in sort comparison at - line 604.
"my $a" used in sort comparison at - line 605.
"my $a" used in sort comparison at - line 606.
"my $a" used in sort comparison at - line 607.
"my $a" used in sort comparison at - line 608.
"my $b" used in sort comparison at - line 703.
"my $b" used in sort comparison at - line 704.
"my $b" used in sort comparison at - line 705.
"my $b" used in sort comparison at - line 706.
"my $b" used in sort comparison at - line 707.
"my $b" used in sort comparison at - line 708.
"my $b" used in sort comparison at - line 803.
"my $b" used in sort comparison at - line 804.
"my $b" used in sort comparison at - line 805.
"my $b" used in sort comparison at - line 806.
"my $b" used in sort comparison at - line 807.
"my $b" used in sort comparison at - line 808.
"my $b" used in sort comparison at - line 903.
"my $b" used in sort comparison at - line 904.
"my $b" used in sort comparison at - line 905.
"my $b" used in sort comparison at - line 906.
"my $b" used in sort comparison at - line 907.
"my $b" used in sort comparison at - line 908.
"my $a" used in sort comparison at - line 1003.
"my $b" used in sort comparison at - line 1003.
"my $a" used in sort comparison at - line 1004.
"my $b" used in sort comparison at - line 1004.
"my $a" used in sort comparison at - line 1005.
"my $b" used in sort comparison at - line 1005.
"my $b" used in sort comparison at - line 1006.
"my $a" used in sort comparison at - line 1006.
"my $b" used in sort comparison at - line 1007.
"my $a" used in sort comparison at - line 1007.
"my $b" used in sort comparison at - line 1008.
"my $a" used in sort comparison at - line 1008.
"my $a" used in sort comparison at - line 1103.
"my $b" used in sort comparison at - line 1103.
"my $a" used in sort comparison at - line 1104.
"my $b" used in sort comparison at - line 1104.
"my $a" used in sort comparison at - line 1105.
"my $b" used in sort comparison at - line 1105.
"my $b" used in sort comparison at - line 1106.
"my $a" used in sort comparison at - line 1106.
"my $b" used in sort comparison at - line 1107.
"my $a" used in sort comparison at - line 1107.
"my $b" used in sort comparison at - line 1108.
"my $a" used in sort comparison at - line 1108.
"my $a" used in sort comparison at - line 1203.
"my $b" used in sort comparison at - line 1203.
"my $a" used in sort comparison at - line 1204.
"my $b" used in sort comparison at - line 1204.
"my $a" used in sort comparison at - line 1205.
"my $b" used in sort comparison at - line 1205.
"my $b" used in sort comparison at - line 1206.
"my $a" used in sort comparison at - line 1206.
"my $b" used in sort comparison at - line 1207.
"my $a" used in sort comparison at - line 1207.
"my $b" used in sort comparison at - line 1208.
"my $a" used in sort comparison at - line 1208.
########
# op.c [S_simplify_sort]
use warnings 'syntax'; use 5.01;
state $a;
sort { $a <=> $b } ();
EXPECT
"state $a" used in sort comparison at - line 4.
########
# op.c [Perl_ck_cmp]
use warnings 'syntax' ;
no warnings 'deprecated';
@a = $[ < 5;
@a = $[ > 5;
@a = $[ <= 5;
@a = $[ >= 5;
@a = 42 < $[;
@a = 42 > $[;
@a = 42 <= $[;
@a = 42 >= $[;
use integer;
@a = $[ < 5;
@a = $[ > 5;
@a = $[ <= 5;
@a = $[ >= 5;
@a = 42 < $[;
@a = 42 > $[;
@a = 42 <= $[;
@a = 42 >= $[;
no integer;
@a = $[ < $5;
@a = $[ > $5;
@a = $[ <= $5;
@a = $[ >= $5;
@a = $42 < $[;
@a = $42 > $[;
@a = $42 <= $[;
@a = $42 >= $[;
use integer;
@a = $[ < $5;
@a = $[ > $5;
@a = $[ <= $5;
@a = $[ >= $5;
@a = $42 < $[;
@a = $42 > $[;
@a = $42 <= $[;
@a = $42 >= $[;
EXPECT
$[ used in numeric lt (<) (did you mean $] ?) at - line 4.
$[ used in numeric gt (>) (did you mean $] ?) at - line 5.
$[ used in numeric le (<=) (did you mean $] ?) at - line 6.
$[ used in numeric ge (>=) (did you mean $] ?) at - line 7.
$[ used in numeric lt (<) (did you mean $] ?) at - line 8.
$[ used in numeric gt (>) (did you mean $] ?) at - line 9.
$[ used in numeric le (<=) (did you mean $] ?) at - line 10.
$[ used in numeric ge (>=) (did you mean $] ?) at - line 11.
$[ used in numeric lt (<) (did you mean $] ?) at - line 13.
$[ used in numeric gt (>) (did you mean $] ?) at - line 14.
$[ used in numeric le (<=) (did you mean $] ?) at - line 15.
$[ used in numeric ge (>=) (did you mean $] ?) at - line 16.
$[ used in numeric lt (<) (did you mean $] ?) at - line 17.
$[ used in numeric gt (>) (did you mean $] ?) at - line 18.
$[ used in numeric le (<=) (did you mean $] ?) at - line 19.
$[ used in numeric ge (>=) (did you mean $] ?) at - line 20.
########
# op.c [Perl_ck_length]
use warnings 'syntax' ;
length(@a);
length(%b);
length(@$c);
length(%$d);
length($a);
length(my %h);
length(my @g);
EXPECT
length() used on @a (did you mean "scalar(@a)"?) at - line 3.
length() used on %b (did you mean "scalar(keys %b)"?) at - line 4.
length() used on @array (did you mean "scalar(@array)"?) at - line 5.
length() used on %hash (did you mean "scalar(keys %hash)"?) at - line 6.
length() used on %h (did you mean "scalar(keys %h)"?) at - line 8.
length() used on @g (did you mean "scalar(@g)"?) at - line 9.
########
# op.c
use warnings 'syntax' ;
join /---/, 'x', 'y', 'z';
EXPECT
/---/ should probably be written as "---" at - line 3.
########
# op.c
use utf8;
use open qw( :utf8 :std );
use warnings 'syntax' ;
join /~~~/, 'x', 'y', 'z';
EXPECT
/~~~/ should probably be written as "~~~" at - line 5.
########
# op.c [Perl_peep]
use warnings 'prototype' ;
fred() ;
sub fred ($$) {}
no warnings 'prototype' ;
joe() ;
sub joe ($$) {}
EXPECT
main::fred() called too early to check prototype at - line 3.
########
# op.c [Perl_newATTRSUB]
--FILE-- abc.pm
use warnings 'void' ;
BEGIN { $| = 1; print "in begin\n"; }
CHECK { print "in check\n"; }
INIT { print "in init\n"; }
END { print "in end\n"; }
print "in mainline\n";
1;
--FILE--
use abc;
delete $INC{"abc.pm"};
require abc;
do "abc.pm";
EXPECT
in begin
in mainline
in check
in init
in begin
Too late to run CHECK block at abc.pm line 3.
Too late to run INIT block at abc.pm line 4.
in mainline
in begin
Too late to run CHECK block at abc.pm line 3.
Too late to run INIT block at abc.pm line 4.
in mainline
in end
in end
in end
########
# op.c [Perl_newATTRSUB]
--FILE-- abc.pm
no warnings 'void' ;
BEGIN { $| = 1; print "in begin\n"; }
CHECK { print "in check\n"; }
INIT { print "in init\n"; }
END { print "in end\n"; }
print "in mainline\n";
1;
--FILE--
require abc;
do "abc.pm";
EXPECT
in begin
in mainline
in begin
in mainline
in end
in end
########
# op.c
my @x;
use warnings 'syntax' ;
push(@x);
unshift(@x);
no warnings 'syntax' ;
push(@x);
unshift(@x);
EXPECT
Useless use of push with no values at - line 4.
Useless use of unshift with no values at - line 5.
########
# op.c
# 20020401 mjd@plover.com at suggestion of jfriedl@yahoo.com
use warnings 'regexp';
split /blah/g, "blah";
no warnings 'regexp';
split /blah/g, "blah";
EXPECT
Use of /g modifier is meaningless in split at - line 4.
########
# op.c
use warnings 'precedence';
$a = $b & $c == $d;
$a = $b ^ $c != $d;
$a = $b | $c > $d;
$a = $b < $c & $d;
$a = $b >= $c ^ $d;
$a = $b <= $c | $d;
$a = $b <=> $c & $d;
$a &= $b == $c; $a |= $b == $c; $a ^= $b == $c; # shouldn't warn
no warnings 'precedence';
$a = $b & $c == $d;
$a = $b ^ $c != $d;
$a = $b | $c > $d;
$a = $b < $c & $d;
$a = $b >= $c ^ $d;
$a = $b <= $c | $d;
$a = $b <=> $c & $d;
EXPECT
Possible precedence problem on bitwise & operator at - line 3.
Possible precedence problem on bitwise ^ operator at - line 4.
Possible precedence problem on bitwise | operator at - line 5.
Possible precedence problem on bitwise & operator at - line 6.
Possible precedence problem on bitwise ^ operator at - line 7.
Possible precedence problem on bitwise | operator at - line 8.
Possible precedence problem on bitwise & operator at - line 9.
########
# op.c
use integer;
use warnings 'precedence';
$a = $b & $c == $d;
$a = $b ^ $c != $d;
$a = $b | $c > $d;
$a = $b < $c & $d;
$a = $b >= $c ^ $d;
$a = $b <= $c | $d;
$a = $b <=> $c & $d;
no warnings 'precedence';
$a = $b & $c == $d;
$a = $b ^ $c != $d;
$a = $b | $c > $d;
$a = $b < $c & $d;
$a = $b >= $c ^ $d;
$a = $b <= $c | $d;
$a = $b <=> $c & $d;
EXPECT
Possible precedence problem on bitwise & operator at - line 4.
Possible precedence problem on bitwise ^ operator at - line 5.
Possible precedence problem on bitwise | operator at - line 6.
Possible precedence problem on bitwise & operator at - line 7.
Possible precedence problem on bitwise ^ operator at - line 8.
Possible precedence problem on bitwise | operator at - line 9.
Possible precedence problem on bitwise & operator at - line 10.
########
# op.c
# ok => local() has desired effect;
# ignore=> local() silently ignored
use warnings 'syntax';
local(undef); # OP_UNDEF ignore
sub lval : lvalue {};
local(lval()); # OP_ENTERSUB
local($x **= 1); # OP_POW
local($x *= 1); # OP_MULTIPLY
local($x /= 1); # OP_DIVIDE
local($x %= 1); # OP_MODULO
local($x x= 1); # OP_REPEAT
local($x += 1); # OP_ADD
local($x -= 1); # OP_SUBTRACT
local($x .= 1); # OP_CONCAT
local($x <<= 1); # OP_LEFT_SHIFT
local($x >>= 1); # OP_RIGHT_SHIFT
local($x &= 1); # OP_BIT_AND
local($x ^= 1); # OP_BIT_XOR
local($x |= 1); # OP_BIT_OR
{
use integer;
local($x *= 1); # OP_I_MULTIPLY
local($x /= 1); # OP_I_DIVIDE
local($x %= 1); # OP_I_MODULO
local($x += 1); # OP_I_ADD
local($x -= 1); # OP_I_SUBTRACT
}
local($x?$y:$z) = 1; # OP_COND_EXPR ok
# these two are fatal run-time errors instead
#local(@$a); # OP_RV2AV ok
#local(%$a); # OP_RV2HV ok
local(*a); # OP_RV2GV ok
local(@a[1,2]); # OP_ASLICE ok
local(@a{1,2}); # OP_HSLICE ok
local(@a = (1,2)); # OP_AASSIGN
local($$x); # OP_RV2SV ok
local($#a); # OP_AV2ARYLEN
local($x = 1); # OP_SASSIGN
local($x &&= 1); # OP_ANDASSIGN
local($x ||= 1); # OP_ORASSIGN
local($x //= 1); # OP_DORASSIGN
local($a[0]); # OP_AELEMFAST ok
local(substr($x,0,1)); # OP_SUBSTR
local(pos($x)); # OP_POS
local(vec($x,0,1)); # OP_VEC
local($a[$b]); # OP_AELEM ok
local($a{$b}); # OP_HELEM ok
no warnings 'syntax';
EXPECT
Useless localization of subroutine entry at - line 10.
Useless localization of exponentiation (**) at - line 11.
Useless localization of multiplication (*) at - line 12.
Useless localization of division (/) at - line 13.
Useless localization of modulus (%) at - line 14.
Useless localization of repeat (x) at - line 15.
Useless localization of addition (+) at - line 16.
Useless localization of subtraction (-) at - line 17.
Useless localization of concatenation (.) or string at - line 18.
Useless localization of left bitshift (<<) at - line 19.
Useless localization of right bitshift (>>) at - line 20.
Useless localization of bitwise and (&) at - line 21.
Useless localization of bitwise xor (^) at - line 22.
Useless localization of bitwise or (|) at - line 23.
Useless localization of integer multiplication (*) at - line 26.
Useless localization of integer division (/) at - line 27.
Useless localization of integer modulus (%) at - line 28.
Useless localization of integer addition (+) at - line 29.
Useless localization of integer subtraction (-) at - line 30.
Useless localization of list assignment at - line 39.
Useless localization of array length at - line 41.
Useless localization of scalar assignment at - line 42.
Useless localization of logical and assignment (&&=) at - line 43.
Useless localization of logical or assignment (||=) at - line 44.
Useless localization of defined or assignment (//=) at - line 45.
Useless localization of substr at - line 48.
Useless localization of match position at - line 49.
Useless localization of vec at - line 50.
########
# op.c
my $x1 if 0;
my @x2 if 0;
my %x3 if 0;
my ($x4) if 0;
my ($x5,@x6, %x7) if 0;
0 && my $z1;
0 && my (%z2);
# these shouldn't warn
our $x if 0;
our $x unless 0;
if (0) { my $w1 }
if (my $w2) { $a=1 }
if ($a && (my $w3 = 1)) {$a = 2}
EXPECT
Deprecated use of my() in false conditional at - line 2.
Deprecated use of my() in false conditional at - line 3.
Deprecated use of my() in false conditional at - line 4.
Deprecated use of my() in false conditional at - line 5.
Deprecated use of my() in false conditional at - line 6.
Deprecated use of my() in false conditional at - line 7.
Deprecated use of my() in false conditional at - line 8.
########
# op.c
$[ = 1;
($[) = 1;
use warnings 'deprecated';
$[ = 2;
($[) = 2;
no warnings 'deprecated';
$[ = 3;
($[) = 3;
EXPECT
Use of assignment to $[ is deprecated at - line 2.
Use of assignment to $[ is deprecated at - line 3.
Use of assignment to $[ is deprecated at - line 5.
Use of assignment to $[ is deprecated at - line 6.
########
# op.c
use warnings 'void';
@x = split /y/, "z";
$x = split /y/, "z";
split /y/, "z";
no warnings 'void';
@x = split /y/, "z";
$x = split /y/, "z";
split /y/, "z";
EXPECT
Useless use of split in void context at - line 5.
########
# op.c
use warnings 'redefine' ;
use utf8;
use open qw( :utf8 :std );
sub frèd {}
sub frèd {}
no warnings 'redefine' ;
sub frèd {}
EXPECT
Subroutine frèd redefined at - line 6.
########
# op.c
use warnings 'redefine' ;
use utf8;
use open qw( :utf8 :std );
sub frèd () { 1 }
sub frèd () { 1 }
no warnings 'redefine' ;
sub frèd () { 1 }
EXPECT
Constant subroutine frèd redefined at - line 6.
########
# op.c
use utf8;
use open qw( :utf8 :std );
sub frèd () { 1 }
sub frèd () { 2 }
EXPECT
Constant subroutine frèd redefined at - line 5.
########
# op.c
use utf8;
use open qw( :utf8 :std );
sub frèd () { 1 }
*frèd = sub () { 2 };
EXPECT
Constant subroutine main::frèd redefined at - line 5.
########
# op.c
use warnings 'redefine' ;
use utf8;
use open qw( :utf8 :std );
sub ᚠርƊ {}
sub ᚠርƊ {}
no warnings 'redefine' ;
sub ᚠርƊ {}
EXPECT
Subroutine ᚠርƊ redefined at - line 6.
########
# op.c
use warnings 'redefine' ;
use utf8;
use open qw( :utf8 :std );
sub ᚠርƊ () { 1 }
sub ᚠርƊ () { 1 }
no warnings 'redefine' ;
sub ᚠርƊ () { 1 }
EXPECT
Constant subroutine ᚠርƊ redefined at - line 6.
########
# op.c
use utf8;
use open qw( :utf8 :std );
sub ᚠርƊ () { 1 }
sub ᚠርƊ () { 2 }
EXPECT
Constant subroutine ᚠርƊ redefined at - line 5.
########
# op.c
use utf8;
use open qw( :utf8 :std );
sub ᚠርƊ () { 1 }
*ᚠርƊ = sub () { 2 };
EXPECT
Constant subroutine main::ᚠርƊ redefined at - line 5.
########
# OPTION regex
sub DynaLoader::dl_error {};
use warnings;
# We're testing that the warnings report the same line number:
eval <<'EOC' or die $@;
{
DynaLoader::boot_DynaLoader("DynaLoader");
}
EOC
eval <<'EOC' or die $@;
BEGIN {
DynaLoader::boot_DynaLoader("DynaLoader");
}
1
EOC
EXPECT
OPTION regex
\ASubroutine DynaLoader::dl_error redefined at \(eval 1\) line 2\.
?(?s).*
Subroutine DynaLoader::dl_error redefined at \(eval 2\) line 2\.
########
# op.c
use warnings;
sub do_warn_1 { return $a or $b; }
sub do_warn_2 { return $a and $b; }
sub do_warn_3 { return $a xor $b; }
sub do_warn_4 { die $a or $b; }
sub do_warn_5 { die $a and $b; }
sub do_warn_6 { die $a xor $b; }
sub do_warn_7 { exit $a or $b; }
sub do_warn_8 { exit $a and $b; }
sub do_warn_9 { exit $a xor $b; }
# Since exit is an unary operator, it is even stronger than
# || and &&.
sub do_warn_10 { exit $a || $b; }
sub do_warn_11 { exit $a && $b; }
sub do_warn_12 { goto $a or $b; }
sub do_warn_13 { goto $a and $b; }
sub do_warn_14 { goto $a xor $b; }
sub do_warn_15 { next $a or $b while(1); }
sub do_warn_16 { next $a and $b while(1); }
sub do_warn_17 { next $a xor $b while(1); }
sub do_warn_18 { last $a or $b while(1); }
sub do_warn_19 { last $a and $b while(1); }
sub do_warn_20 { last $a xor $b while(1); }
sub do_warn_21 { redo $a or $b while(1); }
sub do_warn_22 { redo $a and $b while(1); }
sub do_warn_23 { redo $a xor $b while(1); }
# These get re-written to "(return/die $a) and $b"
sub do_warn_24 { $b if return $a; }
sub do_warn_25 { $b if die $a; }
EXPECT
Possible precedence issue with control flow operator at - line 3.
Possible precedence issue with control flow operator at - line 4.
Possible precedence issue with control flow operator at - line 5.
Possible precedence issue with control flow operator at - line 6.
Possible precedence issue with control flow operator at - line 7.
Possible precedence issue with control flow operator at - line 8.
Possible precedence issue with control flow operator at - line 9.
Possible precedence issue with control flow operator at - line 10.
Possible precedence issue with control flow operator at - line 11.
Possible precedence issue with control flow operator at - line 15.
Possible precedence issue with control flow operator at - line 16.
Possible precedence issue with control flow operator at - line 18.
Possible precedence issue with control flow operator at - line 19.
Possible precedence issue with control flow operator at - line 20.
Possible precedence issue with control flow operator at - line 21.
Possible precedence issue with control flow operator at - line 22.
Possible precedence issue with control flow operator at - line 23.
Possible precedence issue with control flow operator at - line 24.
Possible precedence issue with control flow operator at - line 25.
Possible precedence issue with control flow operator at - line 26.
Possible precedence issue with control flow operator at - line 27.
Possible precedence issue with control flow operator at - line 28.
Possible precedence issue with control flow operator at - line 29.
Possible precedence issue with control flow operator at - line 31.
Possible precedence issue with control flow operator at - line 32.
########
# op.c
# (same as above, except these should not warn)
use constant FEATURE => 1;
use constant MISSING_FEATURE => 0;
sub dont_warn_1 { MISSING_FEATURE and return or dont_warn_3(); }
sub dont_warn_2 { FEATURE || return and dont_warn_3(); }
sub dont_warn_3 { not FEATURE and return or dont_warn_3(); }
sub dont_warn_4 { !MISSING_FEATURE || return and dont_warn_3(); }
sub dont_warn_5 { MISSING_FEATURE and die or dont_warn_3(); }
sub dont_warn_6 { FEATURE || die and dont_warn_3(); }
sub dont_warn_7 { not FEATURE and die or dont_warn_3(); }
sub dont_warn_8 { !MISSING_FEATURE || die and dont_warn_3(); }
sub dont_warn_9 { MISSING_FEATURE and goto $a or dont_warn_3(); }
sub dont_warn_10 { FEATURE || goto $a and dont_warn_3(); }
sub dont_warn_11 { not FEATURE and goto $a or dont_warn_3(); }
sub dont_warn_12 { !MISSING_FEATURE || goto $a and dont_warn_3(); }
sub dont_warn_13 { MISSING_FEATURE and exit $a or dont_warn_3(); }
sub dont_warn_14 { FEATURE || exit $a and dont_warn_3(); }
sub dont_warn_15 { not FEATURE and exit $a or dont_warn_3(); }
sub dont_warn_16 { !MISSING_FEATURE || exit $a and dont_warn_3(); }
sub dont_warn_17 { MISSING_FEATURE and next or dont_warn_3() while(1); }
sub dont_warn_18 { FEATURE || next and dont_warn_3() while(1); }
sub dont_warn_19 { not FEATURE and next or dont_warn_3() while(1); }
sub dont_warn_20 { !MISSING_FEATURE || next and dont_warn_3() while(1); }
sub dont_warn_21 { MISSING_FEATURE and redo or dont_warn_3() while(1); }
sub dont_warn_22 { FEATURE || redo and dont_warn_3() while(1); }
sub dont_warn_23 { not FEATURE and redo or dont_warn_3() while(1); }
sub dont_warn_24 { !MISSING_FEATURE || redo and dont_warn_3() while(1); }
sub dont_warn_25 { MISSING_FEATURE and last or dont_warn_3() while(1); }
sub dont_warn_26 { FEATURE || last and dont_warn_3() while(1); }
sub dont_warn_27 { not FEATURE and last or dont_warn_3() while(1); }
sub dont_warn_28 { !MISSING_FEATURE || last and dont_warn_3() while(1); }
# These are weird, but at least not ambiguous.
sub dont_warn_29 { return ($a or $b); }
sub dont_warn_30 { return ($a and $b); }
sub dont_warn_31 { return ($a xor $b); }
sub dont_warn_32 { die ($a or $b); }
sub dont_warn_33 { die ($a and $b); }
sub dont_warn_34 { die ($a xor $b); }
sub dont_warn_35 { goto ($a or $b); }
sub dont_warn_36 { goto ($a and $b); }
sub dont_warn_37 { goto ($a xor $b); }
sub dont_warn_38 { next ($a or $b) while(1); }
sub dont_warn_39 { next ($a and $b) while(1); }
sub dont_warn_40 { next ($a xor $b) while(1); }
sub dont_warn_41 { last ($a or $b) while(1); }
sub dont_warn_42 { last ($a and $b) while(1); }
sub dont_warn_43 { last ($a xor $b) while(1); }
sub dont_warn_44 { redo ($a or $b) while(1); }
sub dont_warn_45 { redo ($a and $b) while(1); }
sub dont_warn_46 { redo ($a xor $b) while(1); }
EXPECT
|