This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Warn when list-assigning to TEMP
authorFather Chrysostomos <sprout@cpan.org>
Wed, 1 Jun 2011 21:11:37 +0000 (14:11 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 1 Jun 2011 21:38:52 +0000 (14:38 -0700)
ext/XS-APItest/t/lvalue.t
pp_hot.c

index 718507a..d348ea6 100644 (file)
@@ -3,7 +3,7 @@
 use warnings;
 use strict;
 
-use Test::More tests => 3;
+use Test::More tests => 4;
 
 use XS::APItest 'lv_temp_object';
 
@@ -16,6 +16,10 @@ use XS::APItest 'lv_temp_object';
     lv_temp_object() = 75;
     like $w, qr/Useless assignment to a temporary at/,
        'warning when assigning to temp returned from XS lv sub';
+    undef $w;
+    (lv_temp_object()) = 75;
+    like $w, qr/Useless assignment to a temporary at/,
+       'warning when list-assigning to temp returned from XS lv sub';
 
     $w = undef;
     {
index bb0f205..9dffb98 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1112,6 +1112,14 @@ PP(pp_aassign)
                break;
            }
            if (relem <= lastrelem) {
+               if (
+                 SvTEMP(sv) && !SvSMAGICAL(sv) && SvREFCNT(sv) == 1 &&
+                 (!isGV_with_GP(sv) || SvFAKE(sv)) && ckWARN(WARN_MISC)
+               )
+                   Perl_warner(aTHX_
+                      packWARN(WARN_MISC),
+                     "Useless assignment to a temporary"
+                   );
                sv_setsv(sv, *relem);
                *(relem++) = sv;
            }