Message-ID: <
000701c0b56e$73944220$07bdfea9@bfs.phone.com>
A variable will be checked for the "use once" warnings if:
1. It is in the scope of a use warnings 'once'
2. It isn't in the scope of the warnings pragma at all AND $^W is set.
Otherwise it won't be checked at all.
Part 1 is what is in perl >= 5.6.0, Part 2 is what I'm fixing.
The enclosed patch partially fixes this issue. What I didn't
get to work was the case where the "used once" warning is enabled
in any file other than the main file.
p4raw-id: //depot/perl@9401
gv_init(gv, stash, name, len, add & GV_ADDMULTI);
gv_init_sv(gv, sv_type);
- if (isLEXWARN_on && isALPHA(name[0]) && ! ckWARN(WARN_ONCE))
+ if (isALPHA(name[0]) && ! (isLEXWARN_on ? ckWARN(WARN_ONCE)
+ : (PL_dowarn & G_WARN_ON ) ) )
GvMULTI_on(gv) ;
/* set up magic where warranted */
use warnings 'once' ;
$x = 3 ;
EXPECT
+########
+# perl.c
+{ use warnings 'once' ; $x = 3 ; }
+$y = 3 ;
+EXPECT
+Name "main::x" used only once: possible typo at - line 3.
+########
+
+# perl.c
+$z = 3 ;
+BEGIN { $^W = 1 }
+{ no warnings 'once' ; $x = 3 ; }
+$y = 3 ;
+EXPECT
+Name "main::y" used only once: possible typo at - line 6.