This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
attributes.xs: Don’t emit const warning for anons
authorFather Chrysostomos <sprout@cpan.org>
Thu, 22 Jan 2015 05:37:01 +0000 (21:37 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 22 Jan 2015 05:38:14 +0000 (21:38 -0800)
The intent was to emit the warning for any cases other than custom
attributes on anonymous subs.  I did that by checking to see whether
we had a closure prototype, warning otherwise.  But anonymous subs
that are not closures are not closure prototypes.  So we need to
check CvANON instead.

ext/attributes/attributes.xs
t/op/attrs.t

index b1dd60f..9c9ec11 100644 (file)
@@ -48,7 +48,7 @@ modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
                    if (negated)
                        CvANONCONST_off(sv);
                    else {
-                       const bool warn = (!CvCLONE(sv) || CvCLONED(sv))
+                       const bool warn = (!CvANON(sv) || CvCLONED(sv))
                                       && !CvANONCONST(sv);
                        CvANONCONST_on(sv);
                        if (warn)
index f8515fb..b93ed74 100644 (file)
@@ -407,7 +407,9 @@ is $ProtoTest::Proto, '$', 'prototypes are visible in attr handlers';
         attributes->import(shift, shift, lc shift) if $_[2]; ()
     }
     $_ = 32487;
-    my $sub = sub : Const { $_ };
+    my $sub = eval '+sub : Const { $_ }';
+    ::is $w, '',
+     'no warning for :const applied to closure protosub via attributes.pm';
     undef $_;
     ::is &$sub, 32487,
         'applying const attr via attributes.pm';