c++/8209: Failure to detect negative bit-field size (!)
Tim Prince
tprince@computer.org
Sun Oct 13 08:26:00 GMT 2002
The following reply was made to PR c++/8209; it has been noted by GNATS.
From: Tim Prince <tprince@computer.org>
To: wwieser@gmx.de, gcc-gnats@gcc.gnu.org
Cc:
Subject: Re: c++/8209: Failure to detect negative bit-field size (!)
Date: Sun, 13 Oct 2002 08:18:24 -0700
On Sunday 13 October 2002 02:01, wwieser@gmx.de wrote:
> If you compile the following code:
> struct A
> {
> int : (-1);
> };
> you get the (correct) _error_
> negative width in bit-field `A::<anonymous>'
>
> Now, if you compile
> struct A
> {
> int : (sizeof(int)-5);
> };
> then you just get the _warning_
> warning: width of `A::<anonymous>' exceeds its type
> which is incorrect.
>
> As a result, sizeof(A) turns out to be 536870912
> (500Mb).
>
>
It looks like your headers might make size_t an unsigned type, but you
haven't showed that. Here's what my gcc installation has to say in <gc.h>:
/* The ANSI standard suggests that size_t and ptr_diff_t might be */
/* better choices. But those appear to have incorrect definitions */
/* on may systems. Notably "typedef int size_t" seems to be both */
/* frequent and WRONG. */
Maybe the author's failure to check spelling reduces his/her credibility, but
you can see there is a documented opinion on this subject.
As I read the info page, if you wanted warnings from -Wconversion, should
size_t be defined in accordance with the above prejudices, you should get
them with
sizeof(int) +(-5).
--
Tim Prince
More information about the Gcc-prs
mailing list