summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mg.c2
-rw-r--r--t/op/tie.t16
2 files changed, 17 insertions, 1 deletions
diff --git a/mg.c b/mg.c
index 54791cb07f..69c5f4ee06 100644
--- a/mg.c
+++ b/mg.c
@@ -536,7 +536,7 @@ Perl_mg_localize(pTHX_ SV *sv, SV *nsv, bool setmagic)
mg->mg_ptr, mg->mg_len);
/* container types should remain read-only across localization */
- SvFLAGS(nsv) |= SvREADONLY(sv);
+ if (!SvIsCOW(sv)) SvFLAGS(nsv) |= SvREADONLY(sv);
}
if (SvTYPE(nsv) >= SVt_PVMG && SvMAGIC(nsv)) {
diff --git a/t/op/tie.t b/t/op/tie.t
index b485f62d62..0b53b140ef 100644
--- a/t/op/tie.t
+++ b/t/op/tie.t
@@ -1014,3 +1014,19 @@ print "ok\n";
EXPECT
ok
+########
+#
+# Localising a tied COW scalar should not make it read-only.
+
+sub TIESCALAR { bless [] }
+sub FETCH { __PACKAGE__ }
+sub STORE {}
+tie $x, "";
+"$x";
+{
+ local $x;
+ $x = 3;
+}
+print "ok\n";
+EXPECT
+ok