develooper Front page | perl.perl5.porters | Postings from July 2003

[perl #23061] Division by zero should be run time error, not compile time

From:
Ed Avis
Date:
July 20, 2003 13:56
Subject:
[perl #23061] Division by zero should be run time error, not compile time
Message ID:
rt-23061-61498.15.5209969308176@rt.perl.org
# New Ticket Created by  Ed Avis 
# Please include the string:  [perl #23061]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=23061 >


This is a bug report for perl from ed@membled.com,
generated with the help of perlbug 1.26 running under perl 5.008.


-----------------------------------------------------------------
[Please enter your report here]
#!/usr/bin/perl
use warnings;
use strict;
use constant N => 0;
if (N == 0) {
    exit();
}
print 1 / N;

This fails with 'Illegal division by zero at /home/ed/ttt line 8.',
even though there is an explicit check so that the division never
happens if N is set to zero.

Evaluating constant expressions at compile time is a useful
optimation, but it shouldn't break programs that would otherwise work.

I think the above program worked fine with perl 5.005.  For more
precedent, look at what C does:

#include <stdio.h>
int main(void)
{
	const int N = 0;
	if (N == 0) exit();
	printf("%d\n", 1 / N);
	return 0;
}

This is a legal program and the compiler does not complain about the
division by zero (at least, gcc -Wall -O3 does not).  Any error
happens at run time, and only if the code is reached.

[Please do not change anything below this line]
-----------------------------------------------------------------

---
This perlbug was built using Perl 5.00503 - Thu Aug 10 15:31:56 EDT 2000
It is being executed now by  Perl 5.008 - Sat Apr 12 10:55:50 BST 2003.

Site configuration information for perl 5.008:

Configured by tomc at Sat Apr 12 10:55:50 BST 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.2.19-6.2.12.1rs, archname=i686-linux
    uname='linux budvar.future-i.net 2.2.19-6.2.12.1rs #1 sat nov 3 02:42:38 cst 2001 i686 unknown '
    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=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='-O2',
    cppflags='-fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)', 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=-lbind -lnsl -lgdbm -ldl -lm -lc -lcrypt -lutil
    perllibs=-lbind -lnsl -ldl -lm -lc -lcrypt -lutil
    libc=/lib/libc-2.2.4.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.2.4'
  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 5.008:
    /home/ed/lib/perl5/5.8.0/i686-linux
    /home/ed/lib/perl5/5.8.0
    /home/ed/lib/perl5/site_perl/5.8.0/i686-linux
    /home/ed/lib/perl5/site_perl/5.8.0
    /home/ed/lib/perl5/site_perl/5.8.0/i686-linux
    /home/ed/lib/perl5/site_perl/5.8.0/i386-linux
    /home/ed/lib/perl5/site_perl/5.8.0/i686-linux
    /home/ed/lib/perl5/site_perl/5.8.0
    /home/ed/lib/perl5/site_perl
    /usr/lib/perl5/5.8.0/i686-linux
    /usr/lib/perl5/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/i686-linux
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl/5.6.1
    /usr/lib/perl5/site_perl/5.005
    /usr/lib/perl5/site_perl
    .

---
Environment for perl 5.008:
    HOME=/home/ed
    LANG=en_US
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/home/ed/lib:/home/ed/wine/inst/lib:/usr/local/lib
    LOGDIR (unset)
    PATH=/home/ed/bin:/home/ed/bin/i686-pc-linux-gnu:/home/ed/wine/inst/bin:/home/ed/lib/ant/bin:/bin:/usr/bin:/usr/local/maple/bin:/usr/local/bin:/usr/X11R6/bin:/usr/local/java/bin:/var/qmail/bin:/usr/local/pgsql-7.1.3/bin:/usr/local/ezmlm/bin:/opt/kde/bin:/usr/local/X11/bin:/usr/krb5/bin:/usr/athena/bin:/sbin:/usr/sbin:/opt/IBMJava2-13/bin:/usr/local/jdk1.2.2/bin:/usr/share/smlnj/bin:/usr/games:/usr/kerberos/bin:/usr/kerberos/sbin:/usr/libexec/openssh
    PERL5LIB=/home/ed/lib/perl5/5.8.0:/home/ed/lib/perl5/site_perl/5.8.0:/home/ed/lib/perl5/site_perl/5.8.0/i686-linux:/home/ed/lib/perl5/site_perl/5.8.0/i386-linux:/home/ed/lib/perl5/site_perl
    PERL_BADLANG (unset)
    SHELL=/bin/bash




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