diff options
author | Tomasz Konojacki <me@xenu.pl> | 2020-12-30 14:03:02 +0100 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2020-12-30 07:29:22 -0700 |
commit | 07319fdbb283f93cb655c3106b5237cbc7272038 (patch) | |
tree | 4f15778ae23dce3cfd771ef03559906725de556d /op.c | |
parent | 4cfbe5474a5c5f852a6dbf0138dc796c2800be93 (diff) | |
download | perl-07319fdbb283f93cb655c3106b5237cbc7272038.tar.gz |
op.c: croak on "my $_" when "use utf8" is in effect
Fixes #18449
Diffstat (limited to 'op.c')
-rw-r--r-- | op.c | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -730,6 +730,7 @@ PADOFFSET Perl_allocmy(pTHX_ const char *const name, const STRLEN len, const U32 flags) { PADOFFSET off; + bool is_idfirst, is_default; const bool is_our = (PL_parser->in_my == KEY_our); PERL_ARGS_ASSERT_ALLOCMY; @@ -738,14 +739,15 @@ Perl_allocmy(pTHX_ const char *const name, const STRLEN len, const U32 flags) Perl_croak(aTHX_ "panic: allocmy illegal flag bits 0x%" UVxf, (UV)flags); + is_idfirst = flags & SVf_UTF8 + ? isIDFIRST_utf8_safe((U8*)name + 1, name + len) + : isIDFIRST_A(name[1]); + + /* $_, @_, etc. */ + is_default = len == 2 && name[1] == '_'; + /* complain about "my $<special_var>" etc etc */ - if ( len - && !( is_our - || isALPHA(name[1]) - || ( (flags & SVf_UTF8) - && isIDFIRST_utf8_safe((U8 *)name+1, name + len)) - || (name[1] == '_' && len > 2))) - { + if (!is_our && (!is_idfirst || is_default)) { const char * const type = PL_parser->in_my == KEY_sigvar ? "subroutine signature" : PL_parser->in_my == KEY_state ? "\"state\"" : "\"my\""; |