Skip to content

dereferencing result of ternary operator skips autovivification #18669

Description

@spuelrich

Description
Using the ternary conditional operator together with autovivification and dereferencing works no more in v5.32.

Steps to Reproduce

Example 1: Push a value onto a dereferenced hash entry, which does not yet exist:

> perl -MData::Dumper -wE 'my $x={arr=>undef}; push( @{$x->{decide} ? $x->{not_there} : $x->{new}} , "nana"); say Data::Dumper::Dumper($x)'
Not an ARRAY reference at -e line 1.

Example 2: Pushing onto an existing, but undefined hash entry

> perl -MData::Dumper -wE 'my $x={arr=>undef}; push( @{$x->{decide} ? $x->{not_there} : $x->{arr}} , "nana"); say Data::Dumper::Dumper($x)'
Not an ARRAY reference at -e line 1.

Problem can be reproduced with strawberry perl and self-compiled perl under linux.

Expected behavior
Same code works with older perl v5.30.3.1

Example 1:

> perl -MData::Dumper -wE 'my $x={arr=>undef}; push( @{$x->{decide} ? $x->{not_there} : $x->{new}} , "nana"); say Data::Dumper::Dumper($x)'
$VAR1 = {
          'new' => [
                     'nana'
                   ],
          'arr' => undef
        };

Example 2:

> perl -MData::Dumper -wE 'my $x={arr=>undef}; push( @{$x->{decide} ? $x->{not_there} : $x->{arr}} , "nana"); say Data::Dumper::Dumper($x)'
$VAR1 = {
          'arr' => [
                     'nana'
                   ]
        };

Perl configuration

Summary of my perl5 (revision 5 version 32 subversion 0) configuration:

  Platform:
    osname=linux
    osvers=4.12.14-95.54-default
    archname=x86_64-linux
    uname='linux sles12sp4 4.12.14-95.54-default #1 smp thu jun 4 12:49:28 utc 2020 (892ef1f) x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Dprefix=/opt/perl-5.32.0/ -Duserelocatableinc -Duse64bitint'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O2'
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion=''
    gccversion='4.8.5'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib64/gcc/x86_64-suse-linux/4.8/include-fixed /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/lib /usr/lib /lib/../lib64 /usr/lib/../lib64 /lib /lib64 /usr/lib64 /usr/local/lib64
    libs=-lpthread -lnsl -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.22.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.22'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'


Characteristics of this binary (from libperl):
  Compile-time options:
    HAS_TIMES
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under linux
  Compiled at Dec 14 2020 15:22:37
  @INC:
    /work/perl/v5.32.0.1/linux/lib/site_perl/5.32.0/x86_64-linux
    /work/perl/v5.32.0.1/linux/lib/site_perl/5.32.0
    /work/perl/v5.32.0.1/linux/lib/5.32.0/x86_64-linux
    /work/perl/v5.32.0.1/linux/lib/5.32.0

Activity

  1. jkeenan commented on Mar 30, 2021

    @jkeenan
    Contributor

    Description
    Using the ternary conditional operator together with autovivification and dereferencing works no more in v5.32.

    Bisecting with the following invocation:

    perl Porting/bisect.pl --start=44523d1ffd --end=0cf01644e9 -e 'my $x={arr=>undef}; eval { push( @{$x->{decide} ? $x->{not_there} : $x->{new}} , "nana"); }; $@ and exit 1;exit 0'
    

    ... I got:

    e9b0092a1019a24f6bb26933c7b796c2b733d11f is the first bad commit
    
    commit e9b0092a1019a24f6bb26933c7b796c2b733d11f
    Author: David Mitchell <davem@iabyn.com>
    Date:   Fri May 31 11:58:11 2019 +0100
    Commit:     David Mitchell <davem@iabyn.com>
    CommitDate: Mon Jun 24 11:40:07 2019 +0100
    
    
        Perl_doref(): make non-recursive
    

    @iabyn, can you take a look?

    Thank you very much.
    Jim Keenan

  2. jkeenan commented on Aug 3, 2025

    @jkeenan
    Contributor

    @iabyn, could you review this older ticket and the newer one with a TODO test for it? Thanks.

  3. jkeenan commented on Nov 4, 2025

    @jkeenan
    Contributor

    @iabyn, could you review this older ticket and the newer one with a TODO test for it? Thanks.

    @iabyn ^^

  4. iabyn commented on Nov 4, 2025

    @iabyn
    Contributor
  5. added a commit that references this issue on Nov 4, 2025
  6. added a commit that references this issue on Nov 5, 2025
  7. iabyn commented on Nov 12, 2025

    @iabyn
    Contributor

    Now fixed in blead by v5.43.4-111-g39d060cbfc

  8. added a commit that references this issue on Nov 12, 2025
  9. added a commit that references this issue on Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions