This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
returning short-enum and truncate doesn't trigger conversion warning
- From: Paulo Matos <pmatos at broadcom dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Wed, 19 Mar 2014 14:33:27 +0000
- Subject: returning short-enum and truncate doesn't trigger conversion warning
- Authentication-results: sourceware.org; auth=none
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