From ea238638ab35cef3a59dff8b7a19970b7d76c1fd Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Mon, 4 Nov 2013 06:14:00 -0800 Subject: [PATCH] =?utf8?q?[perl=20#120462]=20Exempt=20$a=20and=20$b=20from?= =?utf8?q?=20=E2=80=98used=20once=E2=80=99=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ext/B/t/optree_varinit.t | 30 +++++++++++++++--------------- gv.c | 13 +++++++++++-- op.c | 2 -- t/lib/warnings/1global | 12 ++++++------ t/lib/warnings/gv | 4 ++++ 5 files changed, 36 insertions(+), 25 deletions(-) diff --git a/ext/B/t/optree_varinit.t b/ext/B/t/optree_varinit.t index 3287179..ca2b59b 100644 --- a/ext/B/t/optree_varinit.t +++ b/ext/B/t/optree_varinit.t @@ -108,9 +108,9 @@ EOT_EOT # 3 <$> gvsv(*a) s/OURINTR ->4 EONT_EONT -checkOptree ( name => 'local $a', - prog => 'local $a', - errs => ['Name "main::a" used only once: possible typo at -e line 1.'], +checkOptree ( name => 'local $c', + prog => 'local $c', + errs => ['Name "main::c" used only once: possible typo at -e line 1.'], bcopts => '-basic', strip_open_hints => 1, expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); @@ -118,13 +118,13 @@ checkOptree ( name => 'local $a', 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v:>,<,%,{ ->3 - <1> ex-rv2sv vKM/129 ->4 -3 <#> gvsv[*a] s/LVINTRO ->4 +3 <#> gvsv[*c] s/LVINTRO ->4 EOT_EOT # 4 <@> leave[1 ref] vKP/REFC ->(end) # 1 <0> enter ->2 # 2 <;> nextstate(main 1 -e:1) v:>,<,%,{ ->3 # - <1> ex-rv2sv vKM/129 ->4 -# 3 <$> gvsv(*a) s/LVINTRO ->4 +# 3 <$> gvsv(*c) s/LVINTRO ->4 EONT_EONT pass("MY, OUR, LOCAL, BOTH SUB AND MAIN, = undef"); @@ -238,9 +238,9 @@ EOT_EOT # 4 <$> gvsv(*a) s/OURINTR ->5 EONT_EONT -checkOptree ( name => 'local $a=undef', - prog => 'local $a=undef', - errs => ['Name "main::a" used only once: possible typo at -e line 1.'], +checkOptree ( name => 'local $c=undef', + prog => 'local $c=undef', + errs => ['Name "main::c" used only once: possible typo at -e line 1.'], note => 'locals are rare, probably not worth doing', bcopts => '-basic', strip_open_hints => 1, @@ -251,7 +251,7 @@ checkOptree ( name => 'local $a=undef', 5 <2> sassign vKS/2 ->6 3 <0> undef s ->4 - <1> ex-rv2sv sKRM*/129 ->5 -4 <#> gvsv[*a] s/LVINTRO ->5 +4 <#> gvsv[*c] s/LVINTRO ->5 EOT_EOT # 6 <@> leave[1 ref] vKP/REFC ->(end) # 1 <0> enter ->2 @@ -259,7 +259,7 @@ EOT_EOT # 5 <2> sassign vKS/2 ->6 # 3 <0> undef s ->4 # - <1> ex-rv2sv sKRM*/129 ->5 -# 4 <$> gvsv(*a) s/LVINTRO ->5 +# 4 <$> gvsv(*c) s/LVINTRO ->5 EONT_EONT checkOptree ( name => 'sub {my $a=()}', @@ -359,9 +359,9 @@ EOT_EOT # 6 <@> leave[1 ref] vKP/REFC EONT_EONT -checkOptree ( name => 'local $a=()', - prog => 'local $a=()', - errs => ['Name "main::a" used only once: possible typo at -e line 1.'], +checkOptree ( name => 'local $c=()', + prog => 'local $c=()', + errs => ['Name "main::c" used only once: possible typo at -e line 1.'], #todo => 'probly not worth doing', bcopts => '-exec', strip_open_hints => 1, @@ -369,14 +369,14 @@ checkOptree ( name => 'local $a=()', 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:>,<,%,{ 3 <0> stub sP -4 <#> gvsv[*a] s/LVINTRO +4 <#> gvsv[*c] s/LVINTRO 5 <2> sassign vKS/2 6 <@> leave[1 ref] vKP/REFC EOT_EOT # 1 <0> enter # 2 <;> nextstate(main 1 -e:1) v:>,<,%,{ # 3 <0> stub sP -# 4 <$> gvsv(*a) s/LVINTRO +# 4 <$> gvsv(*c) s/LVINTRO # 5 <2> sassign vKS/2 # 6 <@> leave[1 ref] vKP/REFC EONT_EONT diff --git a/gv.c b/gv.c index 905d131..62652fe 100644 --- a/gv.c +++ b/gv.c @@ -1670,10 +1670,10 @@ S_gv_magicalize(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, PERL_ARGS_ASSERT_GV_MAGICALIZE; if (stash != PL_defstash) { /* not the main stash */ - /* We only have to check for three names here: EXPORT, ISA + /* We only have to check for a few names here: a, b, EXPORT, ISA and VERSION. All the others apply only to the main stash or to CORE (which is checked right after this). */ - if (len > 2) { + if (len) { const char * const name2 = name + 1; switch (*name) { case 'E': @@ -1688,6 +1688,11 @@ S_gv_magicalize(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, if (strEQ(name2, "ERSION")) GvMULTI_on(gv); break; + case 'a': + case 'b': + if (len == 1 && sv_type == SVt_PV) + GvMULTI_on(gv); + /* FALL THROUGH */ default: goto try_core; } @@ -2016,6 +2021,10 @@ S_gv_magicalize(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, SvREFCNT_dec(sv); } break; + case 'a': + case 'b': + if (len == 1 && sv_type == SVt_PV) + GvMULTI_on(gv); } } diff --git a/op.c b/op.c index 5f48939..111da3c 100644 --- a/op.c +++ b/op.c @@ -9902,8 +9902,6 @@ S_simplify_sort(pTHX_ OP *o) PERL_ARGS_ASSERT_SIMPLIFY_SORT; - GvMULTI_on(gv_fetchpvs("a", GV_ADD|GV_NOTQUAL, SVt_PV)); - GvMULTI_on(gv_fetchpvs("b", GV_ADD|GV_NOTQUAL, SVt_PV)); kid = kUNOP->op_first; /* get past null */ if (!(have_scopeop = kid->op_type == OP_SCOPE) && kid->op_type != OP_LEAVE) diff --git a/t/lib/warnings/1global b/t/lib/warnings/1global index 2c54e37..51acd17 100644 --- a/t/lib/warnings/1global +++ b/t/lib/warnings/1global @@ -10,25 +10,25 @@ EXPECT ######## -w # warnable code, warnings enabled via command line switch -$a =+ 3 ; +$c =+ 3 ; EXPECT Reversed += operator at - line 3. -Name "main::a" used only once: possible typo at - line 3. +Name "main::c" used only once: possible typo at - line 3. ######## #! perl -w # warnable code, warnings enabled via #! line -$a =+ 3 ; +$c =+ 3 ; EXPECT Reversed += operator at - line 3. -Name "main::a" used only once: possible typo at - line 3. +Name "main::c" used only once: possible typo at - line 3. ######## # warnable code, warnings enabled via compile time $^W BEGIN { $^W = 1 } -$a =+ 3 ; +$c =+ 3 ; EXPECT Reversed += operator at - line 4. -Name "main::a" used only once: possible typo at - line 4. +Name "main::c" used only once: possible typo at - line 4. ######## -w # warnable code, warnings enabled via command line switch diff --git a/t/lib/warnings/gv b/t/lib/warnings/gv index 67ee1d4..f3334456 100644 --- a/t/lib/warnings/gv +++ b/t/lib/warnings/gv @@ -130,6 +130,10 @@ $x = 1; if ($x) { print $y; } +$a++; # These two should +$b++; # be exempt. +$Foo::a++; +$Foo::b++; EXPECT Name "main::y" used only once: possible typo at - line 5. Use of uninitialized value $y in print at - line 5. -- 2.7.4