Hi all,

This is either a C standard subtlety or a bug in GCC.
For example:
unsigned short foo (unsigned int a)
{
  return a;
}

enum xpto
{
  A = 0,
  B = 1,
  X = 512
};

extern void print (unsigned int);

unsigned char bar (enum xpto a)
{
  print (sizeof (unsigned char));
  print (sizeof (enum xpto));
  return a;
}

$ ~/work/tmp/GCC/builds/gcc-trunk/gcc/cc1 -O2 test.c -Wall -Wconversion 
--short-enums -quiet
test.c: In function 'foo':
test.c:3:3: warning: conversion to 'short unsigned int' from 'unsigned int' may 
alter its value [-Wconversion]
   return a;
   ^

I was expecting a warning for bar as well since sizeof unsigned char is 1 and 
sizeof enum xpto is 2, therefore the value is truncated but no warning is 
issued.

Shall I open a PR?

Paulo Matos


Reply via email to