Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.91k stars 542 forks source link

'my' with 'if 0' retains old value #8135

Closed p5pRT closed 16 years ago

p5pRT commented 18 years ago

Migrated from rt.perl.org#37315 (status was 'rejected')

Searchable as RT37315$

p5pRT commented 18 years ago

From herington_dean@emc.com

This is a bug report for perl from herington_dean@​emc.com \mailto​:herington\_dean@​emc\.com \, generated with the help of perlbug 1.35 running under perl v5.8.4.


Running the following program outputs​:   Perl 5.008004   undef   undef   undef   2 but it should output​:   Perl 5.008004   undef   undef   undef   undef

#!/usr/bin/perl -w

print "Perl $]\n";

sub show {   my ($val) = @​_;   if (! defined $val) {   print "undef\n";   } else {   print "$val\n";   } }

sub sb {

  my $v1;   $v1 = -1 if 0;

  my $v2 = -2 if 0;

  show $v1;   show $v2;

  $v1 = 1;   $v2 = 2;

}

sb; sb;



Flags​:   category=core   severity=high


Site configuration information for perl v5.8.4​:

Summary of my perl5 (revision 5 version 8 subversion 4) configuration​:   Platform​:   osname=solaris\, osvers=2.10\, archname=sun4-solaris-64int   uname='sunos localhost 5.10 sun4u sparc SUNW\,Ultra-2'   config_args=''   hint=recommended\, useposix=true\, d_sigaction=define   usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef   useperlio=define d_sfio=undef uselargefiles=define usesocks=undef   use64bitint=define use64bitall=undef uselongdouble=undef   usemymalloc=n\, bincompat5005=undef   Compiler​:   cc='cc'\, ccflags ='-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -xarch=v8 -D_TS_ERRNO'\,   optimize='-xO3 -xspace -xildoff'\,   cppflags=''   ccversion='Sun WorkShop'\, gccversion=''\, gccosandvers=''   intsize=4\, longsize=4\, ptrsize=4\, doublesize=8\, byteorder=87654321   d_longlong=define\, longlongsize=8\, d_longdbl=define\, longdblsize=16   ivtype='long long'\, ivsize=8\, nvtype='double'\, nvsize=8\, Off_t='off_t'\, lseeksize=8   alignbytes=8\, prototype=define   Linker and Libraries​:   ld='cc'\, ldflags =''   libpth=/lib /usr/lib /usr/ccs/lib   libs=-lsocket -lnsl -ldl -lm -lc   perllibs=-lsocket -lnsl -ldl -lm -lc   libc=/lib/libc.so\, so=so\, useshrplib=true\, libperl=libperl.so   gnulibc_version=''   Dynamic Linking​:   dlsrc=dl_dlopen.xs\, dlext=so\, d_dlsymun=undef\, ccdlflags='-R /usr/perl5/5.8.4/lib/sun4-solaris-64int/CORE'   cccdlflags='-KPIC'\, lddlflags='-G'

Locally applied patches​:   22667 The optree builder was looping when constructing the ops ...   22715 Upgrade to FileCache 1.04   22733 Missing copyright in the README.   22746 fix a coredump caused by rv2gv not fully converting a PV ...   22755 Fix 29149 - another UTF8 cache bug hit by substr.   22774 [perl #28938] split could leave an array without ...   22775 [perl #29127] scalar delete of empty slice returned garbage   22776 [perl #28986] perl -e \"open m\" crashes Perl   22777 add test for change #22776 (\"open m\" crashes Perl)   22778 add test for change #22746 ([perl #29102] Crash on assign ...   22781 [perl #29340] Bizarre copy of ARRAY make sure a pad op's ...   22796 [perl #29346] Double warning for int(undef) and abs(undef) ...   22818 BOM-marked and (BOMless) UTF-16 scripts not working   22823 [perl #29581] glob() misses a lot of matches   22827 Smoke [5.9.2] 22818 FAIL(F) MSWin32 WinXP/.Net SP1 (x86/1 cpu)   22830 [perl #29637] Thread creation time is hypersensitive   22831 improve hashing algorithm for ptr tables in perl_clone​: ...   22839 [perl #29790] Optimization busted​: '@​a \mailto​:'@​a = \"b\"\, sort @​a' ...   22850 [PATCH] 'perl -v' fails if local_patches contains code snippets   22852 TEST needs to ignore SCM files   22886 Pod​::Find should ignore SCM files and dirs   22888 Remove redundant %SIG assignments from FileCache   23006 [perl #30509] use encoding and \"eq\" cause memory leak   23074 Segfault using HTML​::Entities   23106 Numeric comparison operators mustn't compare addresses of ...   23320 [perl #30066] Memory leak in nested shared data structures ...   23321 [perl #31459] Bug in read()


@​INC for perl v5.8.4​:   /usr/perl5/5.8.4/lib/sun4-solaris-64int   /usr/perl5/5.8.4/lib   /usr/perl5/site_perl/5.8.4/sun4-solaris-64int   /usr/perl5/site_perl/5.8.4   /usr/perl5/site_perl   /usr/perl5/vendor_perl/5.8.4/sun4-solaris-64int   /usr/perl5/vendor_perl/5.8.4   /usr/perl5/vendor_perl   .


Environment for perl v5.8.4​:   HOME=/emc/dheringt   LANG (unset)   LANGUAGE (unset)   LC_COLLATE=en_US.ISO8859-1   LC_CTYPE=en_US.ISO8859-1   LC_MESSAGES=C   LC_MONETARY=en_US.ISO8859-1   LC_NUMERIC=en_US.ISO8859-1   LC_TIME=en_US.ISO8859-1   LD_LIBRARY_PATH (unset)   LOGDIR (unset)

PATH=.​:/emc/dheringt/bin​:/usr/local/project/pp/tools/sparc_solaris/bin​:/usr/ bin​:/usr/local/bin​:/usr/ucb​:/usr/bin​:   PERL_BADLANG (unset)   SHELL=/bin/csh

p5pRT commented 18 years ago

From charles.e.derykus@boeing.com

This is a bug report for perl from herington_dean@​emc.com \mailto​:herington\_dean@​emc\.com \, generated with the help of > > perlbug 1.35 running under perl v5.8.4.

Use of 'my $v if 0' is deprecated. Please see​:

http​://groups.google.com/group/perl.perl5.porters/browse_frm/thread/e665 bd4eefa7771c/7f2a47223bb7cecf?lnk=st&q=%22if+0%22+group​:*perl*&rnum=1&hl =en#7f2a47223bb7cecf

-- Charles DeRykus

p5pRT commented 18 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 18 years ago

From sts@accognoscere.org

On Fri\, Sep 30\, 2005 at 09​:45​:27AM -0700\, herington\, dean wrote​:

Running the following program outputs​: Perl 5.008004 undef undef undef 2 but it should output​: Perl 5.008004 undef undef undef undef

#!/usr/bin/perl -w

print "Perl $]\n";

sub show { my ($val) = @​_; if (! defined $val) { print "undef\n"; } else { print "$val\n"; } }

sub sb {

my $v1;
$v1 = \-1 if 0;

my $v2 = \-2 if 0;

show $v1;
show $v2;

$v1 = 1;
$v2 = 2;

}

sb; sb;

MJD (Mark-Jason Dominus) gave an explanation which is located at​: http​://www.perl.com/pub/a/2000/05/p5pdigest/THISWEEK-20000521.html#my_x_if_0%3B_Trick

The according thread on p5p​: http​://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-05/msg00621.html

p5pRT commented 16 years ago

p5p@spam.wizbit.be - Status changed from 'open' to 'rejected'