From: Keith Thompson <kst-u@mib.org>
Subject: Re: Division by zero
Date: Tue, 14 Jun 2005 08:35:26 GMT
Date: 2005-06-14T08:35:26+00:00 [thread overview]
Message-ID: <lnacltqqsx.fsf@nuthaus.mib.org> (raw)
In-Reply-To: i9rre.3963$jX6.435@newsread2.news.pas.earthlink.net
Jeffrey Carter <spam@spam.com> writes:
[...]
> I suppose a compiler could tell if "/" had been redefined for a type,
> and produce warnings only in the case where it had not, but I don't
> know of any compilers that do.
I do:
% gcc --version
gcc (GCC) 4.0.0
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% cat -n foo.adb
1 procedure Foo is
2 X : Integer := 1;
3 Y : Integer := 1;
4 begin
5 declare
6 function "/"(Left, Right: Integer) return Integer is
7 begin
8 return Right;
9 end "/";
10 begin
11 X := X / 0;
12 X := 1 / 0;
13 end;
14 Y := Y / 0;
15 Y := 1 / 0;
16 end Foo;
% gcc -c foo.adb
foo.adb:14:14: warning: division by zero
foo.adb:14:14: warning: "Constraint_Error" will be raised at run time
foo.adb:15:12: division by zero
foo.adb:15:12: static expression raises "Constraint_Error"
I'd be surprised if this weren't the case. By the time the compiler
is deciding whether to issue a warning, it knows that the "/" being
invoked is a user-defined operator rather than a predefined operator
(and probably doesn't care that its name is "/").
If a compiler issued a warning on a call to a user-defined "/"
function with a second parameter of 0, I'd consider it a bug (unless
it was a result of an analysis of the actual function).
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
next prev parent reply other threads:[~2005-06-14 8:35 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-11 21:03 Division by zero Lurker
2005-06-12 2:00 ` David C. Hoos, Sr.
2005-06-12 3:04 ` Lurker
2005-06-12 8:39 ` Dmitry A. Kazakov
2005-06-12 9:43 ` Lurker
2005-06-12 10:36 ` Marius Amado Alves
2005-06-12 11:53 ` Dmitry A. Kazakov
2005-06-13 8:03 ` Ole-Hjalmar Kristensen
2005-06-12 13:10 ` Robert A Duff
2005-06-12 16:55 ` Jeffrey Carter
2005-06-13 3:22 ` Keith Thompson
2005-06-14 2:14 ` Jeffrey Carter
2005-06-13 8:47 ` Lurker
2005-06-14 2:19 ` Jeffrey Carter
2005-06-14 8:35 ` Keith Thompson [this message]
2005-06-13 12:19 ` Robert A Duff
2005-06-14 2:31 ` Jeffrey Carter
2005-06-14 8:21 ` Lurker
2005-06-14 20:22 ` Randy Brukardt
2005-06-28 21:22 ` Robert A Duff
2005-06-29 5:50 ` Lurker
2005-06-29 13:27 ` Robert A Duff
2005-06-29 13:54 ` Dmitry A. Kazakov
2005-06-29 16:03 ` Robert A Duff
2005-06-30 1:19 ` Lurker
2005-06-30 11:16 ` Stuart Palin
2005-06-29 13:50 ` Dmitry A. Kazakov
2005-06-29 16:07 ` Robert A Duff
2005-06-30 8:27 ` Dmitry A. Kazakov
2005-06-29 9:20 ` Lurker
2005-06-29 9:49 ` Christoph Grein
2005-06-29 10:40 ` Lurker
2005-06-29 11:04 ` Jeff Creem
2005-06-29 12:28 ` Martin Dowie
2005-06-29 13:40 ` Robert A Duff
[not found] ` <5sana1pm436l6vboifijqblu0irf84afkr@4ax.com>
2005-06-12 17:38 ` Simon Wright
2005-06-12 12:21 ` Robert A Duff
2005-06-12 22:53 ` Georg Bauhaus
2005-06-13 8:34 ` Lurker
2005-06-13 8:54 ` Marius Amado Alves
2005-06-13 17:59 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox