develooper Front page | perl.perl5.porters | Postings from April 2000

[PATCH op.c 5.6.0] our variable will/will not stay shared

From:
Robin Barker
Date:
April 27, 2000 05:33
Subject:
[PATCH op.c 5.6.0] our variable will/will not stay shared
Message ID:
200004271233.NAA24292@tempest.npl.co.uk
Hi

There seems to be an unnecessary and incorrect warning for C<our>.

% perl5.6.0 -Mstrict -lwe \
	'sub foo {my $x = shift; sub boo  { print $x }}; foo 1; foo 2; boo;'
Variable "$x" will not stay shared at -e line 1.
1

% perl5.6.0 -Mstrict -lwe \
	'sub foo {our $x = shift; sub boo  { print $x }}; foo 1; foo 2; boo;'
Variable "$x" will not stay shared at -e line 1.
2

So, despite the warning, the variable "$x" does stayed shared (as we would
expect).  The patch below suppresses the warning and adds a test.

Robin

--- op.c.orig   Fri Apr 14 15:36:57 2000
+++ op.c        Fri Apr 14 15:41:50 2000
@@ -321,7 +321,8 @@
                        }
                    }
                    else if (!CvUNIQUE(PL_compcv)) {
-                       if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv))
+                       if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv)
+                               && !(SvFLAGS(sv) & SVpad_OUR))
                            Perl_warner(aTHX_ WARN_CLOSURE,
                                "Variable \"%s\" will not stay shared", name);
                    }
--- ./t/pragma/warn/op.orig     Fri Apr 14 15:44:45 2000
+++ ./t/pragma/warn/op  Fri Apr 14 15:48:05 2000
@@ -150,6 +150,17 @@
 # op.c
 use warnings 'closure' ;
 sub x {
+      our $x;
+      sub y {
+         $x
+      }
+   }
+EXPECT
+
+########
+# op.c
+use warnings 'closure' ;
+sub x {
       my $x;
       sub y {
          sub { $x }

-- 
Robin Barker                        | Eail:  Robin.Barker@npl.co.uk
CMSC, Building 10,                  | Phone: +44 (0) 20 8943 7090
National Physical Laboratory,       | Fax:   +44 (0) 20 8977 7091
Teddington, Middlesex, UK. TW11 OLW | WWW:   http://www.npl.co.uk



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About