On 02/06/2015 06:34 AM, Peter Maydell wrote:
> I can't see any nice way of avoiding this. Possible nasty ways:
> 
> (1) Drop the enum and just use old-fashioned
> #define EC_AA64_BKPT 0x3cU
> since then we can force them to be unsigned
> (2) Cast the constant to unsigned at point of use
> (3) Keep the enum and add defines wrapping actual use
> #define EC_AA64_BKPT ((unsigned)EC_AA64_BKPT)
> I guess there's also
> (4) Ignore the problem and trust that the compiler developers will
> never decide to use this bit of undefined behaviour.

It should be enough to simply add the unsigned suffix to the integers as they
are, forcing the underlying type to be unsigned.

At least that's suggested by the simple test case

   extern void link_error(void);
   enum X { bot = 1u } x = bot;
   int main() { if (-x < 0) link_error(); return 0; }

$ clang -O z.c
z.c:3:21: warning: comparison of unsigned expression < 0 is always false
      [-Wtautological-compare]
int main() { if (-x < 0) link_error(); return 0; }
                 ~~ ^ ~
$ gcc -O -Wall z.c
$


r~


Reply via email to