This is the mail archive of the
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
This is either a C standard subtlety or a bug in GCC.
unsigned short foo (unsigned int a)
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));
$ ~/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]
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?