This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Skip warnable const folding outside warnings scope
authorFather Chrysostomos <sprout@cpan.org>
Tue, 9 Sep 2014 13:13:43 +0000 (06:13 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 9 Sep 2014 15:25:52 +0000 (08:25 -0700)
commitc4c61c60d2920ba19f2127f56554142d9173e4fa
tree3bb70e3c580ef9e3d4a3695ce2d2ed7c26670a84
parent5e85836e74be0c9dfe98cb2dc97960fc8716a95f
Skip warnable const folding outside warnings scope

Constant folding is not supposed to warn.  If it would produce a warn-
ing, then it is skipped and the warning is deferred to run time.

This means the -w flag can affect constant folding:

$ ./perl -Ilib -MO=Concise -le 'use constant u=>undef; $a = u+1'
6  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 132 -e:1) v:{ ->3
5     <2> sassign vKS/2 ->6
3        <$> const[NV 1] s/FOLD ->4
-        <1> ex-rv2sv sKRM*/1 ->5
4           <#> gvsv[*a] s ->5
-e syntax OK
$ ./perl -Ilib -MO=Concise -lwe 'use constant u=>undef; $a = u+1'
8  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 132 -e:1) v:{ ->3
7     <2> sassign vKS/2 ->8
5        <2> add[t2] sK/2 ->6
3           <$> const[NULL ] s*/FOLD ->4
4           <$> const[PVNV 1] s ->5
-        <1> ex-rv2sv sKRM*/1 ->7
6           <#> gvsv[*a] s ->7
-e syntax OK

But the problem here is that the flag could be turned on at run time,
so if the folding happens because -w is off, then the behaviour
changes due to folding.  It’s fine to do the folding here only when
warnings are lexically disabled, as that overrides any setting of -w.
op.c
t/comp/fold.t
t/op/coresubs.t