$ ./perl -Ilib -e 'use constant nullrocow => (keys%{{""=>undef}})[0]; for(nullrocow) { y/a/b/ }'
$ ./perl -Ilib -e 'use constant nullro => ""; for(nullro) { y/a/b/ }'
Modification of a read-only value attempted at -e line 1.
It should croak on COW scalars that are read-only, even if they are
zero-length, just as it does on non-COW scalars.
This logic is left over from when READONLY+FAKE meant COW.
PERL_ARGS_ASSERT_DO_TRANS;
if (SvREADONLY(sv) && !(PL_op->op_private & OPpTRANS_IDENTICAL)) {
- if (!SvIsCOW(sv))
Perl_croak_no_modify();
}
(void)SvPV_const(sv, len);
require './test.pl';
}
-plan tests => 132;
+plan tests => 134;
my $Is_EBCDIC = (ord('i') == 0x89 & ord('J') == 0xd1);
is($x, "PerlĪ²", "Only first of multiple transliterations is used");
}
+# tr/a/b/ should fail even on zero-length read-only strings
+use constant nullrocow => (keys%{{""=>undef}})[0];
+for ("", nullrocow) {
+ eval { $_ =~ y/a/b/ };
+ like $@, qr/^Modification of a read-only value attempted at /,
+ 'tr/a/b/ fails on zero-length ro string';
+}
+
1;