Coding Guidelines for Integral Constant Expressions

There may be an error in them. From http://www.boost.org/more/int_const_guidelines.htm: --- An integral constant expression can be one of the following: ... 2. An enumerator value. ... 9. The result of applying a binary operator to two integral constant expressions: INTEGRAL_CONSTANT1 op INTEGRAL_CONSTANT2 provided that the operator is not an assignment operator, or comma operator. --- Neither gcc (3.3.3) nor Metrowerks (don't remember version) seems to think that "enumVal1 | enumVal2" is an integral constant expression. This seems obvious in the case of operator| being overloaded, although Comeau online 4.3.3 *does* seem to swallow that without complaint, which greatly diminishes my expectations of being right and greatly adds to my confusion. However, gcc and Metrowerks seem to ban this even if operator| is not overloaded. I haven't found the standardese to motivate that yet. Someone set me straight, please! Thanks, Johan

Neither gcc (3.3.3) nor Metrowerks (don't remember version) seems to think that "enumVal1 | enumVal2" is an integral constant expression. This seems obvious in the case of operator| being overloaded, although Comeau online 4.3.3 *does* seem to swallow that without complaint, which greatly diminishes my expectations of being right and greatly adds to my confusion. However, gcc and Metrowerks seem to ban this even if operator| is not overloaded. I haven't found the standardese to motivate that yet. Someone set me straight, please!
I couldn't find anything about this except 5.19 where certain specific operators are banned, by deduction everything else should be legal I guess (but not overloaded operators obviously). I guess casting the enum types to int should fix the compiler error (you can even cast back to enum type afterwards if that's what you want), but obviously that only works if you know how wide the enum's are. John.
participants (2)
-
Johan Johansson
-
John Maddock