This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [PATCH] Java: @deprecated handling, division by zero detection.


Tom Tromey wrote:

>However there is a point here -- it seems to me that we have to give
>an error when the division by zero occurs in a constant expression.
>For instance something like this:
>
>    switch (foo)
>      {
>	case 1/0: ...
>
Javac 1.3.1 complains "constant expression required" in this case.

What I think we want is to always warn on "expr/0" or "expr%0",
but to make it a hard error when a constant expression is required.
The latter is sort of what javac does, though with a confusing error
message.  A better error is hard to get in general though, since the
division-by-zero can be in setting some arbitrarily distant
static final field - where it *is* allowed.

Javac's behavior seems straight-forward enough to implement:  Just make a
special case in constant-folding that does not constant-fold EXPR/0 or 
EXPR%0.
If that expression is used in a context where a constant expression is
required, then we will get the "constant expression required" error at that
location.  Combined with a warning at the place where the actual division
occurs, and I think thatt will be fine.

>




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]