Topic: Out-of-range assignment to enum


Author: algrant@myrealbox.com (Al Grant)
Date: Mon, 5 Jan 2004 18:51:39 +0000 (UTC)
Raw View
7.2:9 says "The value is unchanged if it is in the range of enumeration
values of the enumeration type; otherwise the resulting enumeration
value is unspecified".

For a case where C might pick a signed representation, this appears
to be a stronger constraint in C++ than in C, since it implies a C++
implementation must produce an unspecified value (and then carry on)
where C makes no requirement on the implementation (i.e. UB).

Is this an intentional change?  (Obviously, the definition of range
has changed but I believe that is orthogonal here.)  Why doesn't it
just say "the behavior is undefined"?

Stroustrup 3rd edition (4.8, p.77) says "The result of such a
conversion is undefined unless the value is within the range of
the enumeration."  It's not clear whether he means "the result
behavior" or "the result value".  Is there a material difference
between Stroustrup's "undefined" versus the Standard's "unspecified"?

---
[ 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                       ]