This is a bug report for perl from gi...@caliper.activestate.com,
generated with the help of perlbug 1.34 running under perl v5.8.2.
-----------------------------------------------------------------
[Please enter your report here]
Using the literal "" as a false value generates a bogus warning.
$ perl -we 'if ("") { print "Hello;" }'
Useless use of a constant in void context at -e line 1.
$ perl -we 'if ("0") { print "Hello;" }'
Useless use of a constant in void context at -e line 1.
$ perl -we 'if (0) { print "Hello;" }'
$ perl -we 'if (!"1") { print "Hello;" }'
The reason I ended up with "" is that I have a template system that
expands what goes into the string of the perl code.
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=low
---
Site configuration information for perl v5.8.2:
Configured by gisle at Thu Nov 6 00:32:08 PST 2003.
Summary of my perl5 (revision 5.0 version 8 subversion 2) configuration:
Platform:
osname=linux, osvers=2.4.20-8, archname=i686-linux
uname='linux caliper.activestate.com 2.4.20-8 #1 thu mar 13 17:54:28 est 2003 i686 i686 i386 gnulinux '
config_args='-Dprefix=/local/perl/5.8.2 -ders'
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 -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
optimize='-O3',
cppflags='-fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
ccversion='', gccversion='3.2.2 20030222 (Red Hat Linux 3.2.2-5)', 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 -lgdbm -ldb -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='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Locally applied patches:
---
@INC for perl v5.8.2:
/local/perl/5.8.2/lib/5.8.2/i686-linux
/local/perl/5.8.2/lib/5.8.2
/local/perl/5.8.2/lib/site_perl/5.8.2/i686-linux
/local/perl/5.8.2/lib/site_perl/5.8.2
/local/perl/5.8.2/lib/site_perl
.
---
Environment for perl v5.8.2:
HOME=/home/gisle
LANG=en_US.ISO-8859-1
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/home/gisle/bin:/local/perl/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin
PERL_BADLANG (unset)
SHELL=/bin/bash
That's a difficult one. This warning is apparently produced after constant
folding and before optimization. Your if() statement is internally
something like
"" and do { print "Hello;" }
which gets trimmed to
""
which produces the warning, before it gets nullified.
How/why is this different from the "if (0) { ..." case?
Regards,
Gisle
0 and 1 are special cased. (as well as "di", "ds" and "ig", for
historical reasons.)
Frankly, I'd rather not.
> Gisle Aas wrote:
> >
> > How/why is this different from the "if (0) { ..." case?
>
> 0 and 1 are special cased. (as well as "di", "ds" and "ig", for
> historical reasons.)
Can't we special case "" and "0" as well then?
--Gisle
I fully understand this position. I found that I can use the
following workaround
if ("" || 0) { ...
Again, the actual content of "" is expanded from a template. I ended
up with this hack because I wanted the unexpanded program template to
be checkable with 'perl -c'.
--Gisle