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]

Re: New gcc 4.0.0 warnings seem spurious


On Tue April 26 2005 11:10, Joseph S. Myers wrote:
> On Tue, 26 Apr 2005, Bruce Lilly wrote:
> 
> > Demonstration code:
> > --------------------------
> > #define AAA 0x1U
> > #define BBB 0x2U
> > 
> > struct foo {
> >     unsigned int bar:8;
> > };
> > 
> > struct foo foos[] = {
> >     { ~(AAA) },
> >     { ~(BBB) },
> >     { ~(AAA|BBB) },
> >     { ~(AAA&BBB) }
> > };
> > --------------------------
> > 
> > compiling with gcc 3.x produced no warnings, as expected (no problems as
> > all values fit easily within the defined structure's bit field).
> 
> I don't see why you think the warnings are spurious.  ~(AAA), for example, 
> is 4294967294,

No, in this context it is 254 (an 8-bit unsigned field with the LSB clear).

> which being greater than 255 certainly does not fit within  
> the type unsigned:8.

But 254 is certainly < 255.  The 'U' in the constant simply means unsigned;
if it had been specified as "LU" you might have a point.  But it wasn't.

> Previous GCC versions had a long-known bug whereby  
> they did not diagnose this; that bug has been fixed in GCC 4.

Looks more like several bugs were introduced; consider:

#if 0
#define AAA 0x1U
#define BBB 0x2U
#else
static const unsigned char AAA = 0x1U;
static const unsigned char BBB = 0x2U;
#endif

struct foo {
    unsigned int bar:8;
};

struct foo foos[] = {
    { ~(AAA) },
    { ~(BBB) },
    { ~(AAA|BBB) },
    { ~(AAA&BBB) }
};

gcc 4.0.0 reports:

gcctest.c:14: error: initializer element is not constant
gcctest.c:14: error: (near initialization for 'foos[0].bar')
gcctest.c:15: error: initializer element is not constant
gcctest.c:15: error: (near initialization for 'foos[1].bar')
gcctest.c:16: error: initializer element is not constant
gcctest.c:16: error: (near initialization for 'foos[2].bar')
gcctest.c:17: error: initializer element is not constant
gcctest.c:17: error: (near initialization for 'foos[3].bar')

Now it's claiming that two *explicitly declared* const values aren't
constant!


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