summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pp_hot.c5
-rw-r--r--t/op/sub_lval.t7
2 files changed, 10 insertions, 2 deletions
diff --git a/pp_hot.c b/pp_hot.c
index bd0f909025..d66dddee14 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -2611,7 +2611,10 @@ PP(pp_leavesublv)
if (MARK == SP) {
/* Temporaries are bad unless they happen to be elements
* of a tied hash or array */
- if (SvFLAGS(TOPs) & (SVs_TEMP | SVs_PADTMP | SVf_READONLY) &&
+ if ((SvFLAGS(TOPs) & (SVs_TEMP | SVs_PADTMP) ||
+ (SvFLAGS(TOPs) & (SVf_READONLY | SVf_FAKE))
+ == SVf_READONLY
+ ) &&
!(SvRMAGICAL(TOPs) && mg_find(TOPs, PERL_MAGIC_tiedelem))) {
LEAVE;
cxstack_ix--;
diff --git a/t/op/sub_lval.t b/t/op/sub_lval.t
index c20ffac7be..f754782148 100644
--- a/t/op/sub_lval.t
+++ b/t/op/sub_lval.t
@@ -3,7 +3,7 @@ BEGIN {
@INC = '../lib';
require './test.pl';
}
-plan tests=>71;
+plan tests=>73;
sub a : lvalue { my $a = 34; ${\(bless \$a)} } # Return a temporary
sub b : lvalue { ${\shift} }
@@ -570,3 +570,8 @@ Execution of - aborted due to compilation errors.
lval_decl = 5;
is($x, 5, "subroutine declared with lvalue before definition retains lvalue. [perl #68758]");
}
+
+sub fleen : lvalue { $pnare }
+$pnare = __PACKAGE__;
+ok eval { fleen = 1 }, "lvalues can return COWs (CATTLE?) [perl #75656]";\
+is $pnare, 1, 'and returning CATTLE actually works';