develooper Front page | perl.perl5.porters | Postings from August 2009

[perl #68640] Wrong error for undef constant name

Nicholas Clark
August 18, 2009 04:10
[perl #68640] Wrong error for undef constant name
Message ID:
# New Ticket Created by  Nicholas Clark 
# Please include the string:  [perl #68640]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.39 running under perl 5.11.0.

[Please describe your issue here]

$ ./perl -Ilib -we 'use constant undef, 1'
Use of uninitialized value within @_ in hash element at lib/ line 62.
Constant name '' is invalid at -e line 1
BEGIN failed--compilation aborted at -e line 1.

However, given that the code for constant looks like this:

    if ( $multiple ) {
	if (ref $_[0] ne 'HASH') {
	    require Carp;
	    Carp::croak("Invalid reference type '".ref(shift)."' not 'HASH'");
	$constants = shift;
    } else {
	$constants->{+shift} = undef;

    foreach my $name ( keys %$constants ) {
	unless (defined $name) {
	    require Carp;
	    Carp::croak("Can't use undef as constant name");

it seems clear that the intent is that the error should be
"Can't use undef as constant name".

I can see two fixes. One is paranoid, one is fast.

The paranoid fix is to duplicate that C<defined $name> clause into 

	$constants->{+shift} = undef;

This is paranoid because it copes with someone passing in a tied hash that
is capable of returning undefined keys.

The "fast" version is simply to move the check. This gets it out of the loop,
but does mean that we can get tripped up by crazy fools with tied hashes.
But perfect is the enemy of the good - maybe the crazy fools get what they

Nicholas Clark

[Please do not change anything below this line]
Site configuration information for perl 5.11.0:

Configured by nick at Mon Aug 17 12:07:33 BST 2009.

Summary of my perl5 (revision 5 version 11 subversion 0) configuration:
  Local Commit: beb5337c331af7597cf571560e8b7f31c3a90450
  Ancestor: 5115136b5ada1a3245a69b04d93664e445e85eb1
    osname=linux, osvers=2.6.18-xenu, archname=x86_64-linux
    uname='linux zazen 2.6.18-xenu #1 smp thu oct 4 12:23:41 bst 2007 x86_64 gnulinux '
    config_args='-Dusedevel=y -Dcc=ccache gcc -Dld=gcc -Ubincompat5005 -Uinstallusrbinperl -Dinc_version_list=  -Dinc_version_list_init=0 -Doptimize=-g -Uusethreads -Uuse64bitall -Uusemymalloc -Duseperlio -Dprefix=~/Sandpit/snap5.9.x-GitLive-blead-1853-gbeb5337 -Uusevendorprefix -Uvendorprefix=~/Sandpit/snap5.9.x-GitLive-blead-1853-gbeb5337 -Dinstallman1dir=none -Dinstallman3dir=none -Uuserelocatableinc -de'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='ccache gcc', ccflags ='-DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    cppflags='-DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.3.2', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64
    libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -g -L/usr/local/lib -fstack-protector'

Locally applied patches:

@INC for perl 5.11.0:

Environment for perl 5.11.0:
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)
    SHELL=/bin/bash Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About