This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

returning short-enum and truncate doesn't trigger conversion warning


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]