Topic: Defect Report: expressions with invalid results and ill-formedness


Author: gennaro_prota@yahoo.com (Gennaro Prota)
Date: Mon, 19 Jan 2004 01:09:53 +0000 (UTC)
Raw View
Clause 5 [expr] par. 5 of the standard says: "If during the evaluation
of an expression, the result is not mathematically defined or not in
the range of representable values for its type, the behavior is
undefined, unless such an expression is a constant expression (5.19),
in which case the program is ill-formed."

Well, we do know that except in some contexts (e.g. controlling
expression of a #if, array bounds), a compiler is not required to
evaluate constant-expressions in compile time, right?


Now, let us consider, the following simple snippet:

  if (a && 1/0)
      ...

with a, to fix our attention, being *not* a constant expression. The
quote above seems to say that since 1/0 is a constant
(sub-)expression, the program is ill-formed. So, is it the intent that
such ill-formedness is diagnosable at run-time? Or is it the intent
that the above gives undefined behavior (if 1/0 is evaluated) and is
not ill-formed?

I think the intent is actually the latter, so I propose the following
rewording of the quoted section ([expr], par. 5):

  "If an expression is evaluated but its result is not mathema-
   tically defined or not in the range of representable values
   for its type the behavior is undefined, unless such an expression
   is a constant expression (5.19) __that shall be evaluated during
   program translation__, in which case the program is ill-formed."


Genny.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]