Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #24646] if ("") warns

0 views
Skip to first unread message

Gisle Aas

unread,
Dec 12, 2003, 6:02:40 AM12/12/03
to bugs-bi...@netlabs.develooper.com
# New Ticket Created by Gisle Aas
# Please include the string: [perl #24646]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=24646 >

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

Rafael Garcia-Suarez

unread,
Dec 14, 2003, 5:28:09 PM12/14/03
to perl5-...@perl.org
Gisle Aas (via RT) wrote:
> 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.

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.

Gisle Aas

unread,
Dec 14, 2003, 6:03:38 PM12/14/03
to perlbug-...@perl.org

How/why is this different from the "if (0) { ..." case?

Regards,
Gisle

Rafael Garcia-Suarez

unread,
Dec 14, 2003, 6:12:36 PM12/14/03
to Gisle Aas, perlbug-...@perl.org
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.)

Rafael Garcia-Suarez

unread,
Dec 14, 2003, 6:27:32 PM12/14/03
to Gisle Aas, perlbug-...@perl.org
Gisle Aas wrote:
> "Rafael Garcia-Suarez via RT" <perlbug-...@perl.org> writes:
>
> Can't we special case "" and "0" as well then?

Frankly, I'd rather not.

Gisle Aas

unread,
Dec 14, 2003, 6:12:11 PM12/14/03
to perlbug-...@perl.org
"Rafael Garcia-Suarez via RT" <perlbug-...@perl.org> writes:

> 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

Gisle Aas

unread,
Dec 16, 2003, 4:17:41 AM12/16/03
to Rafael Garcia-Suarez, perlbug-...@perl.org
Rafael Garcia-Suarez <rgarci...@free.fr> writes:

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

0 new messages