develooper Front page | perl.perl5.porters | Postings from April 2007

[perl #42664] Wrong warning line with undef value comparison in if/elsif/else

Thread Next
From:
Flavio Poletti
Date:
April 23, 2007 04:22
Subject:
[perl #42664] Wrong warning line with undef value comparison in if/elsif/else
Message ID:
rt-3.6.HEAD-6655-1177285374-624.42664-75-0@perl.org
# New Ticket Created by  Flavio Poletti 
# Please include the string:  [perl #42664]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=42664 >


This is a bug report for perl from polettix@cpan.org,
generated with the help of perlbug 1.35 running under perl v5.8.8.


-----------------------------------------------------------------
I noticed something weird with warnings about undefined values
in comparisons in if/elsif/else. Consider the following script:

   #!/opt/perl/bin/perl          # line  1
   use strict;                   # line  2
   use warnings;                 # line  3
                                 # line  4
   if ('a' eq 'b') {             # line  5
      print "impossible\n"       # line  6
   }                             # line  7
   elsif (undef == 2) {          # line  8
      print "not here\n"         # line  9
   }                             # line 10
   else {                        # line 11
      print "got it!\n"          # line 12
   }                             # line 13

The first comparison in line 5 is false, thus the second one
in line 8 is always checked and leads to a warning due to the
fact that one operand is undefined. I would expect the warning
to point me towards line 8 (i.e. the offending line) but I get
the following:

   poletti@PolettiX:~/sviluppo/perl/half-close$ which perl
   /opt/perl/bin/perl
   poletti@PolettiX:~/sviluppo/perl/half-close$ perl bug.pl
   Use of uninitialized value in numeric eq (==) at bug.pl line 5.
   got it!

The same applies also to the perl 5.8.5 shipped with my Debian
Sarge.

Regards,

   Flavio.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
Site configuration information for perl v5.8.8:

Configured by poletti at Thu Feb  2 12:47:34 CET 2006.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.6.8-2-686, archname=i686-linux
    uname='linux polettix 2.6.8-2-686 #1 tue aug 16 13:22:48 utc 2005 i686
gnulinux '
    config_args='-Dprefix=/opt/perl -des'
    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=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='3.3.5 (Debian 1:3.3.5-13)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:


---
@INC for perl v5.8.8:
    /opt/perl/lib/5.8.8/i686-linux
    /opt/perl/lib/5.8.8
    /opt/perl/lib/site_perl/5.8.8/i686-linux
    /opt/perl/lib/site_perl/5.8.8
    /opt/perl/lib/site_perl
    .

---
Environment for perl v5.8.8:
    HOME=/home/poletti
    LANG=it_IT@euro
    LANGUAGE=it_IT
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/poletti/bin:/opt/local/bin:/opt/perl/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
    PERL_BADLANG (unset)
    SHELL=/bin/bash



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About